Sending to a Multicast Group : MulticastSocket « Network « Java Tutorial






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);
  }
}








19.22.MulticastSocket
19.22.1.Multicast Sender
19.22.2.Multicast Sniffer
19.22.3.Joining a Multicast Group
19.22.4.Receiving from a Multicast Group
19.22.5.Sending to a Multicast Group