public final class TimeUDPClient extends DatagramSocketClient
open and call getTime or getDate to retrieve the time.
Then call close to close the connection properly. Unlike
TimeTCPClient, successive calls to getTime or getDate are permitted without
re-establishing a connection. That is because UDP is a connectionless protocol and the Time protocol is stateless.TimeTCPClient| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_PORT
The default time port.
|
static long |
SECONDS_1900_TO_1970
The number of seconds between 00:00 1 January 1900 and 00:00 1 January 1970.
|
_isOpen_, _socket_, _socketFactory_, _timeout_| Constructor and Description |
|---|
TimeUDPClient()
Constructs a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
Date |
getDate(InetAddress host)
Gets the time from a server and returns a Java Date containing the time converted to the local time zone.
|
Date |
getDate(InetAddress host,
int port)
Gets the time from a server and returns a Java Date containing the time converted to the local time zone.
|
long |
getTime(InetAddress host)
Gets the time from the specified server and default port.
|
long |
getTime(InetAddress host,
int port)
Gets the time from the specified server and port.
|
(package private) static long |
toTime(byte[] timeData) |
checkOpen, close, getCharset, getDefaultTimeout, getLocalAddress, getLocalPort, getSoTimeoutDuration, isOpen, open, open, open, setCharset, setDatagramSocketFactory, setDefaultTimeout, setSoTimeoutpublic static final int DEFAULT_PORT
public static final long SECONDS_1900_TO_1970
public Date getDate(InetAddress host) throws IOException
host - the time-serverIOException - on errorpublic Date getDate(InetAddress host, int port) throws IOException
host - The address of the server.port - The port of the service.IOException - If an error occurs while fetching the time.public long getTime(InetAddress host) throws IOException
host - the time-serverIOException - on errorpublic long getTime(InetAddress host, int port) throws IOException
host - The address of the server.port - The port of the service.IOException - If an error occurs while retrieving the time.static long toTime(byte[] timeData)