public class SntpClient extends Object
SntpClient client = new SntpClient(); if (client.requestTime("time.foo.com")) { long now = client.getNtpTime() + Util.platformTimeMillis() - client.getNtpTimeReference(); }
Constructor and Description |
---|
SntpClient() |
Modifier and Type | Method and Description |
---|---|
long |
getNtpTime()
Returns the time computed from the NTP transaction.
|
long |
getNtpTimeReference()
Returns the reference clock value (value of Util.platformTimeMillis()) corresponding to the NTP time.
|
long |
getRoundTripTime()
Returns the round trip time of the NTP transaction
|
boolean |
requestTime(String host,
int timeout)
Sends an SNTP request to the given host and processes the response.
|
boolean |
requestTime(String host,
int port,
int timeout)
Sends an SNTP request to the given host and processes the response.
|
public long getNtpTime()
public long getNtpTimeReference()
public long getRoundTripTime()
public boolean requestTime(String host, int timeout)
host
- host name of the server.timeout
- network timeout in milliseconds. the timeout doesn't include the DNS lookup time, and it applies to
each individual query to the resolved addresses of the NTP server.public boolean requestTime(String host, int port, int timeout)
host
- host name of the server.port
- port of the server.timeout
- network timeout in milliseconds.