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() |
| Modifier and Type | Method and Description |
|---|---|
Date |
getDate(InetAddress host)
Same as
getTime(host, DEFAULT_PORT); |
Date |
getDate(InetAddress host,
int port)
Retrieves the time from the server and returns a Java Date
containing the time converted to the local timezone.
|
long |
getTime(InetAddress host)
Same as
getTime(host, DEFAULT_PORT); |
long |
getTime(InetAddress host,
int port)
Retrieves the time from the specified server and port and
returns it.
|
close, getCharset, getCharsetName, getDefaultTimeout, getLocalAddress, getLocalPort, getSoTimeout, isOpen, open, open, open, setCharset, setDatagramSocketFactory, setDefaultTimeout, setSoTimeoutpublic static final int DEFAULT_PORT
public static final long SECONDS_1900_TO_1970
public TimeUDPClient()
public 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.public long getTime(InetAddress host) throws IOException
getTime(host, DEFAULT_PORT); 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 Date getDate(InetAddress host) throws IOException
getTime(host, DEFAULT_PORT); host - the time serverIOException - on errorCopyright © 2001–2017 The Apache Software Foundation. All rights reserved.