FileDocCategorySizeDatePackage
DaytimeUDPClient.javaAPI DocApache Commons NET 1.4.1 API2849Sat Dec 03 10:05:48 GMT 2005org.apache.commons.net

DaytimeUDPClient

public final class DaytimeUDPClient extends DatagramSocketClient
The DaytimeUDPClient class is a UDP implementation of a client for the Daytime protocol described in RFC 867. To use the class, merely open a local datagram socket with {@link org.apache.commons.net.DatagramSocketClient#open open } and call {@link #getTime getTime } to retrieve the daytime string, then call {@link org.apache.commons.net.DatagramSocketClient#close close } to close the connection properly. Unlike {@link org.apache.commons.net.DaytimeTCPClient}, successive calls to {@link #getTime getTime } are permitted without re-establishing a connection. That is because UDP is a connectionless protocol and the Daytime protocol is stateless.

author
Daniel F. Savarese
see
DaytimeTCPClient

Fields Summary
public static final int
DEFAULT_PORT
The default daytime port. It is set to 13 according to RFC 867.
private byte[]
__dummyData
private byte[]
__timeData
Constructors Summary
Methods Summary
public java.lang.StringgetTime(java.net.InetAddress host, int port)
Retrieves the time string from the specified server and port and returns it.

param
host The address of the server.
param
port The port of the service.
return
The time string.
exception
IOException If an error occurs while retrieving the time.


                                                   
           
    
        DatagramPacket sendPacket, receivePacket;

        sendPacket =
            new DatagramPacket(__dummyData, __dummyData.length, host, port);
        receivePacket = new DatagramPacket(__timeData, __timeData.length);

        _socket_.send(sendPacket);
        _socket_.receive(receivePacket);

        return new String(receivePacket.getData(), 0, receivePacket.getLength());
    
public java.lang.StringgetTime(java.net.InetAddress host)
Same as getTime(host, DaytimeUDPClient.DEFAULT_PORT);

        return getTime(host, DEFAULT_PORT);