Package android.net
Class SntpClient
- java.lang.Object
-
- android.net.SntpClient
-
public class SntpClient extends Object
Simple SNTP client class for retrieving network time. Sample usage:SntpClient client = new SntpClient(); if (client.requestTime("time.foo.com")) { long now = client.getNtpTime() + Util.platformTimeMillis() - client.getNtpTimeReference(); }
-
-
Constructor Summary
Constructors Constructor Description SntpClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetNtpTime()Returns the time computed from the NTP transaction.longgetNtpTimeReference()Returns the reference clock value (value of Util.platformTimeMillis()) corresponding to the NTP time.longgetRoundTripTime()Returns the round trip time of the NTP transactionbooleanrequestTime(String host, int timeout)Sends an SNTP request to the given host and processes the response.booleanrequestTime(String host, int port, int timeout)Sends an SNTP request to the given host and processes the response.
-
-
-
Method Detail
-
requestTime
public boolean requestTime(String host, int timeout)
Sends an SNTP request to the given host and processes the response.- Parameters:
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.- Returns:
- true if the transaction was successful.
-
requestTime
public boolean requestTime(String host, int port, int timeout)
Sends an SNTP request to the given host and processes the response.- Parameters:
host- host name of the server.port- port of the server.timeout- network timeout in milliseconds.- Returns:
- true if the transaction was successful.
-
getNtpTime
public long getNtpTime()
Returns the time computed from the NTP transaction.- Returns:
- time value computed from NTP server response.
-
getNtpTimeReference
public long getNtpTimeReference()
Returns the reference clock value (value of Util.platformTimeMillis()) corresponding to the NTP time.- Returns:
- reference clock corresponding to the NTP time.
-
getRoundTripTime
public long getRoundTripTime()
Returns the round trip time of the NTP transaction- Returns:
- round trip time in milliseconds.
-
-