You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
818 B

  1. /* Angelehnt an Kurose/Ross Computernetzwerke (bis 5e Java, ab 6e Python) */
  2. package verteiltesysteme.socket.multicast;
  3. import java.net.*;
  4. class UDPMulticastConsumer {
  5. public static void main(String args[]) throws Exception {
  6. String groupname = "224.1.1.1";
  7. int udpPort = 36040;
  8. @SuppressWarnings("resource")
  9. MulticastSocket mcastSocket = new MulticastSocket(udpPort);
  10. InetAddress IPAddress = InetAddress.getByName(groupname);
  11. mcastSocket.joinGroup(IPAddress);
  12. byte[] receiveData = new byte[1024];
  13. while (true) {
  14. DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
  15. mcastSocket.receive(receivePacket);
  16. String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength());
  17. System.out.println(sentence);
  18. }
  19. }
  20. }