FileDocCategorySizeDatePackage
UDPServer.javaAPI DocExample1075Thu Apr 03 15:26:04 BST 1997None

UDPServer

public class UDPServer extends Object

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


       
  
    DatagramPacket incoming;

    int port;
    int len;
    
    try {
      port = Integer.parseInt(args[0]);
    }
    catch (Exception e) {
      port = defaultPort;
    }
    try {
      len = Integer.parseInt(args[1]);
    }
    catch (Exception e) {
      len = defaultBufferLength;
    }

    try {
      DatagramSocket ds = new DatagramSocket(port);
      byte[] buffer = new byte[len];
      incoming = new DatagramPacket(buffer, buffer.length);
      while (true) {
        try {
          ds.receive(incoming);
          respond(ds, incoming);
        }
        catch (IOException e) {
          System.err.println(e);
        }      
      } // end while
    }  // end try
    catch (SocketException se) {
      System.err.println(se);
    }  // end catch

  
public static voidrespond(java.net.DatagramSocket ds, java.net.DatagramPacket dp)

    ;