public class SntpClient
extends java.lang.Object
限定符和类型 | 字段和说明 |
---|---|
private long |
mNtpTime |
private long |
mNtpTimeReference |
private long |
mRoundTripTime |
private static int |
NTP_MODE_CLIENT |
private static int |
NTP_PACKET_SIZE |
private static int |
NTP_PORT |
private static int |
NTP_VERSION |
private static long |
OFFSET_1900_TO_1970 |
private static int |
ORIGINATE_TIME_OFFSET |
private static int |
RECEIVE_TIME_OFFSET |
private static int |
REFERENCE_TIME_OFFSET |
private static java.lang.String |
TAG |
private static int |
TRANSMIT_TIME_OFFSET |
构造器和说明 |
---|
SntpClient() |
限定符和类型 | 方法和说明 |
---|---|
long |
getNtpTime()
Returns the time computed from the NTP transaction. * * @return time value computed from NTP server response.
|
long |
getNtpTimeReference()
Returns the reference clock value (value of SystemClock.elapsedRealtime()) * corresponding to the NTP time. * * @return reference clock corresponding to the NTP time.
|
long |
getRoundTripTime()
Returns the round trip time of the NTP transaction * * @return round trip time in milliseconds.
|
private long |
read32(byte[] buffer,
int offset)
Reads an unsigned 32 bit big endian number from the given offset in the buffer.
|
private long |
readTimeStamp(byte[] buffer,
int offset)
Reads the NTP time stamp at the given offset in the buffer and returns * it as a system time (milliseconds since January 1, 1970).
|
boolean |
requestTime(java.lang.String host,
int timeout)
Sends an SNTP request to the given host and processes the response. * * @param host host name of the server. * @param timeout network timeout in milliseconds. * @return true if the transaction was successful.
|
private void |
writeTimeStamp(byte[] buffer,
int offset,
long time)
Writes system time (milliseconds since January 1, 1970) as an NTP time stamp * at the given offset in the buffer.
|
private static final java.lang.String TAG
private static final int REFERENCE_TIME_OFFSET
private static final int ORIGINATE_TIME_OFFSET
private static final int RECEIVE_TIME_OFFSET
private static final int TRANSMIT_TIME_OFFSET
private static final int NTP_PACKET_SIZE
private static final int NTP_PORT
private static final int NTP_MODE_CLIENT
private static final int NTP_VERSION
private static final long OFFSET_1900_TO_1970
private long mNtpTime
private long mNtpTimeReference
private long mRoundTripTime
public boolean requestTime(java.lang.String host, int timeout)
public long getNtpTime()
public long getNtpTimeReference()
public long getRoundTripTime()
private long read32(byte[] buffer, int offset)
private long readTimeStamp(byte[] buffer, int offset)
private void writeTimeStamp(byte[] buffer, int offset, long time)