FileDocCategorySizeDatePackage
UDPDaytimeServer.javaAPI DocExample855Sun Dec 12 10:53:48 GMT 2004None

UDPDaytimeServer

public class UDPDaytimeServer extends UDPServer

Fields Summary
public static final int
DEFAULT_PORT
Constructors Summary
public UDPDaytimeServer()


      
    super(DEFAULT_PORT); 
  
Methods Summary
public static voidmain(java.lang.String[] args)

 
   try {
     UDPServer server = new UDPDaytimeServer();
     server.start();
   }
   catch (SocketException ex) {
     System.err.println(ex);
   }
 
  
public voidrespond(java.net.DatagramPacket packet)


    try {
      Date now = new Date();
      String response = now.toString() + "\r\n";
      byte[] data = response.getBytes("ASCII");
      DatagramPacket outgoing = new DatagramPacket(data, 
       data.length, packet.getAddress(), packet.getPort());
      socket.send(outgoing);
    }
    catch (IOException ex) {
      System.err.println(ex);
    }