Package org.apache.commons.net.daytime
Class DaytimeUDPClient
- java.lang.Object
-
- org.apache.commons.net.DatagramSocketClient
-
- org.apache.commons.net.daytime.DaytimeUDPClient
-
- All Implemented Interfaces:
java.lang.AutoCloseable
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 withopenand callgetTimeto retrieve the daytime string, then callcloseto close the connection properly. UnlikeDaytimeTCPClient, successive calls togetTimeare 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 intDEFAULT_PORTThe default daytime port.private byte[]dummyDataprivate byte[]timeDataReceived dates should be less than 256 bytes.-
Fields inherited from class org.apache.commons.net.DatagramSocketClient
_isOpen_, _socket_, _socketFactory_, _timeout_
-
-
Constructor Summary
Constructors Constructor Description DaytimeUDPClient()Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetTime(java.net.InetAddress host)Gets the time string from the specified server and port and returns it.java.lang.StringgetTime(java.net.InetAddress host, int port)Gets the time string from the specified server and port and returns it.-
Methods inherited from class org.apache.commons.net.DatagramSocketClient
checkOpen, close, getCharset, getCharsetName, getDefaultTimeout, getDefaultTimeoutDuration, getLocalAddress, getLocalPort, getSoTimeout, getSoTimeoutDuration, isOpen, open, open, open, setCharset, setDatagramSocketFactory, setDefaultTimeout, setDefaultTimeout, setSoTimeout, 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
-
dummyData
private final byte[] dummyData
-
timeData
private final byte[] timeData
Received dates should be less than 256 bytes.
-
-
Method Detail
-
getTime
public java.lang.String getTime(java.net.InetAddress host) throws java.io.IOExceptionGets the time string from the specified server and port and returns it.Shorthand for
getTime(host, DaytimeUDPClient.DEFAULT_PORT);- Parameters:
host- the host- Returns:
- the time
- Throws:
java.io.IOException- on error
-
getTime
public java.lang.String getTime(java.net.InetAddress host, int port) throws java.io.IOExceptionGets 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.
-
-