Package org.apache.commons.net.daytime
Class DaytimeUDPClient
- java.lang.Object
-
- org.apache.commons.net.DatagramSocketClient
-
- org.apache.commons.net.daytime.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 withopen
and callgetTime
to retrieve the daytime string, then callclose
to close the connection properly. UnlikeDaytimeTCPClient
, successive calls togetTime
are permitted without re-establishing a connection. That is because UDP is a connectionless protocol and the Daytime protocol is stateless.- See Also:
DaytimeTCPClient
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PORT
The default daytime port.-
Fields inherited from class org.apache.commons.net.DatagramSocketClient
_isOpen_, _socket_, _socketFactory_, _timeout_
-
-
Constructor Summary
Constructors Constructor Description DaytimeUDPClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getTime(java.net.InetAddress host)
Same asgetTime(host, DaytimeUDPClient.DEFAULT_PORT);
java.lang.String
getTime(java.net.InetAddress host, int port)
Retrieves the time string from the specified server and port and returns it.-
Methods inherited from class org.apache.commons.net.DatagramSocketClient
close, getCharset, getCharsetName, getDefaultTimeout, getLocalAddress, getLocalPort, getSoTimeout, isOpen, open, open, open, setCharset, setDatagramSocketFactory, setDefaultTimeout, setSoTimeout
-
-
-
-
Field Detail
-
DEFAULT_PORT
public static final int DEFAULT_PORT
The default daytime port. It is set to 13 according to RFC 867.- See Also:
- Constant Field Values
-
-
Method Detail
-
getTime
public java.lang.String getTime(java.net.InetAddress host, int port) throws java.io.IOException
Retrieves the time string from the specified server and port and returns it.- Parameters:
host
- The address of the server.port
- The port of the service.- Returns:
- The time string.
- Throws:
java.io.IOException
- If an error occurs while retrieving the time.
-
getTime
public java.lang.String getTime(java.net.InetAddress host) throws java.io.IOException
Same asgetTime(host, DaytimeUDPClient.DEFAULT_PORT);
- Parameters:
host
- the host- Returns:
- the time
- Throws:
java.io.IOException
- on error
-
-