net.i2p.router.time
Class NtpClient

java.lang.Object
  extended by net.i2p.router.time.NtpClient

 class NtpClient
extends Object

NtpClient - an NTP client for Java. This program connects to an NTP server and prints the response to the console. The local clock offset calculation is implemented according to the SNTP algorithm specified in RFC 2030. Note that on windows platforms, the curent time-of-day timestamp is limited to an resolution of 10ms and adversely affects the accuracy of the results.

Since:
0.9.1 moved from net.i2p.time
Author:
Adam Buckley (minor refactoring by jrandom)

Constructor Summary
NtpClient()
           
 
Method Summary
static long currentTime(String serverName)
          Query the given NTP server, returning the current internet time
static long currentTime(String[] serverNames)
          Query the ntp servers, returning the current time from first one we find
static long[] currentTimeAndStratum(String[] serverNames, int perServerTimeout)
          Query the ntp servers, returning the current time from first one we find Hack to return time and stratum
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NtpClient

NtpClient()
Method Detail

currentTime

public static long currentTime(String[] serverNames)
Query the ntp servers, returning the current time from first one we find

Returns:
milliseconds since january 1, 1970 (UTC)
Throws:
IllegalArgumentException - if none of the servers are reachable

currentTimeAndStratum

public static long[] currentTimeAndStratum(String[] serverNames,
                                           int perServerTimeout)
Query the ntp servers, returning the current time from first one we find Hack to return time and stratum

Returns:
time in rv[0] and stratum in rv[1]
Throws:
IllegalArgumentException - if none of the servers are reachable
Since:
0.7.12

currentTime

public static long currentTime(String serverName)
Query the given NTP server, returning the current internet time

Returns:
milliseconds since january 1, 1970 (UTC), or -1 on error