-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynmulticastSend2.java
More file actions
37 lines (32 loc) · 918 Bytes
/
dynmulticastSend2.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 dynmulticastSend2
{
public static void main(String[] args) {
DatagramSocket socket1 = null;
DatagramPacket outPacket1 = null;
byte[] outBuf1;
final int PORT = 8888;
try {
socket1 = new DatagramSocket();
long counter = 0;
String msg;
while (true) {
msg = "This is multicast! " + counter;
counter++;
outBuf1 = msg.getBytes();
//Send to multicast IP address and port
InetAddress address1 = InetAddress.getByName("224.2.2.2");
outPacket1 = new DatagramPacket(outBuf1, outBuf1.length, address1, PORT);
socket1.send(outPacket1);
System.out.println("Server sends : " + msg);
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
}
}
} catch (IOException ioe) {
System.out.println(ioe);
}
}
}