-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynmulticastSend3.java
More file actions
37 lines (32 loc) · 918 Bytes
/
dynmulticastSend3.java
File metadata and controls
37 lines (32 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.io.*;
import java.net.*;
public class dynmulticastSend3
{
public static void main(String[] args) {
DatagramSocket socket2 = null;
DatagramPacket outPacket2 = null;
byte[] outBuf2;
final int PORT = 8888;
try {
socket2 = new DatagramSocket();
long counter = 0;
String msg;
while (true) {
msg = "This is multicast! " + counter;
counter++;
outBuf2 = msg.getBytes();
//Send to multicast IP address and port
InetAddress address2 = InetAddress.getByName("224.2.2.3");
outPacket2 = new DatagramPacket(outBuf2, outBuf2.length, address2, PORT);
socket2.send(outPacket2);
System.out.println("Server sends : " + msg);
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
}
}
} catch (IOException ioe) {
System.out.println(ioe);
}
}
}