Sending to a Multicast Group
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class Main {
public static void main(String[] argv) throws Exception {
byte[] outbuf = new byte[1024];
int port = 1234;
DatagramSocket socket = new DatagramSocket();
InetAddress groupAddr = InetAddress.getByName("8.1.2.3");
DatagramPacket packet = new DatagramPacket(outbuf, outbuf.length, groupAddr, port);
socket.send(packet);
}
}
Related examples in the same category