[Pharo-project] [ANN] ZTimestamp[Precise]SNTPClient

Sven Van Caekenberghe sven at stfx.eu
Tue Feb 26 13:42:11 CET 2013


It is often important, especially for server applications, to know if the current local clock is still OK. The standard way for doing that is part of NTP (http://en.wikipedia.org/wiki/Network_Time_Protocol). I implemented two SNTP clients (one with ZTimestamp's second precision and another one using DateAndTime's nanosecond precision) that can be used to check the difference between the local clock and the clock of any NTP server.

	ZTimestampPreciseSNTPClient new clockDifference. 


This reports that the difference between the local and remote clocks is in the order of 5ms, as computed in one specific way. Other queries are related to the Clock synchronisation algorithm.

	ZTimestampPreciseSNTPClient new localClockOffset. 


	ZTimestampPreciseSNTPClient new roundtripDelay.


In practice the following would be a useful practical check.

	ZTimestampPreciseSNTPClient new
		enforceClockDifference: 2 seconds
		ifFail: [ :delta | 
			self warn: ('Clock difference {1} > 2s' format: { delta }) ];

As NTP uses UDP datagrams, this is a nice example for that as well. The code can be found in the following repository:


It is probably easiest to load the ZTimestamp configuration using the Configuration Browser and then load the bleeding edge version (it is not in de released version). The code is self-contained and loads cleanly.

	ConfigurationOfZTimestamp project bleedingEdge load.

The client contacts a server from pool.ntp.org. The code does only deal with a limited aspect of NTP, which is rather complex and wonderful subject matter (http://tools.ietf.org/html/rfc2030). My goal was to get a dependable result, not be be super accurate.



Sven Van Caekenberghe
Smalltalk is the Red Pill

More information about the Pharo-project mailing list