Receiving from a Multicast Group : DatagramSocket « Network Protocol « Java






Receiving from a Multicast Group

 


import java.net.DatagramPacket;
import java.net.MulticastSocket;

public class Main {
  public static void main(String[] argv) throws Exception {

    MulticastSocket msocket = new MulticastSocket(9999);
    byte[] inbuf = new byte[1024];
    DatagramPacket packet = new DatagramPacket(inbuf, inbuf.length);

    msocket.receive(packet);

    // Data is now in inbuf
    int numBytesReceived = packet.getLength();
  }
}

   
  








Related examples in the same category

1.Use DatagramSocket to send out and receive DatagramPacket
2.DatagramSocket sends out DatagramPacket
3.DatagramSocket receives DatagramPacket
4.Datagram Sender
5.Sending a Datagram
6.Receiving a Datagram
7.Joining a Multicast Group
8.Sending to a Multicast Group
9.Receive DatagramPacket
10.Send a Datagram
11.User Datagram Protocol Programming
12.Read and write with DatagramPacket
13.Send back the response in a DatagramPacket