FileDocCategorySizeDatePackage
UDPDiscardServer.javaAPI DocExample918Thu Apr 03 15:25:50 BST 1997None

UDPDiscardServer

public class UDPDiscardServer extends Object

Fields Summary
public static final int
discardPort
static byte[]
buffer
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


       

    int port;

    try {
      port = Integer.parseInt(args[0]);
    }
    catch (Exception e) {
      port = discardPort;
    }

    try {
      DatagramSocket ds = new DatagramSocket(port);
      DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
      while (true) {
        try {
          ds.receive(dp);
          String s = new String(dp.getData(), 0, 0, dp.getLength());
          System.out.println(dp.getAddress() + " at port " + dp.getPort() + " says " + s);
        }
        catch (IOException e) {
          System.err.println(e);
        }      
       } // end while
    }  // end try
    catch (SocketException se) {
      System.err.println(se);
    }  // end catch