Build 1.0_r1(from source)

android.net
Class SntpClient

java.lang.Object
  extended by 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() + SystemClock.elapsedRealtime() - client.getNtpTimeReference();
 }
 


Constructor Summary
SntpClient()
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SntpClient

public SntpClient()
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.
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 SystemClock.elapsedRealtime()) 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.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature