public class SntpClient extends Object
SntpClient client = new SntpClient();
if (client.requestTime("time.foo.com")) {
long now = client.getNtpTime() + SystemClock.elapsedRealtime() - 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 SystemClock.elapsedRealtime())
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.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.