FileDocCategorySizeDatePackage
MulticastSender.javaAPI DocExample1020Sat Sep 09 20:52:18 BST 2000None

MulticastSender

public class MulticastSender extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

  
    InetAddress ia = null;
    int port = 0;
    byte ttl = (byte) 1;
  
    // read the address from the command line
    try {
      ia = InetAddress.getByName(args[0]);
      port = Integer.parseInt(args[1]);
      if (args.length > 2) ttl = (byte) Integer.parseInt(args[2]);
    }
    catch (Exception e)  {
      System.err.println(e);
      System.err.println(
       "Usage: java MulticastSender multicast_address port ttl");
      System.exit(1);
    }
  
    byte[] data = "Here's some multicast data\r\n".getBytes();
    DatagramPacket dp = new DatagramPacket(data, data.length, ia, port);
  
    try {
      MulticastSocket ms = new MulticastSocket();
      for (int i = 1; i < 10; i++) {
        ms.send(dp, ttl);
      }
      ms.close();
    }
    catch (SocketException se) {
      System.err.println(se);
    }
    catch (IOException ie) {
      System.err.println(ie);
    }