4

I want to synchronize the time with NTP over JavaScript. The client can be a normal pc or a smartphone or tablet. The connection could be WLAN or 3G, etc.

I already found this questions and sites

first and second links using the a timestamp from this server: http://json-time.appspot.com/time.json But the date object has only second precision. I want a better precision, if possible ~ 10 ms. (I know the precision depends on the connection and round trip time)
Edit: 10 ms is almost impossible. I want the most precision offset.

The third link shows a JavaScript library, but it does not use a direct connection to a ntp server. The solution of the fourth link is most near to that what I want. But its for synchronizing two clients through a 'own' server. Is there a way to synchronize it directly to a ntp pool like pool.ntp.org ?

Community
  • 1
  • 1
timaschew
  • 16,254
  • 6
  • 61
  • 78
  • `Pinging 8.8.8.8 with 32 bytes of data: Reply from 8.8.8.8: bytes=32 time=68ms TTL=44 Ping statistics for 8.8.8.8: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 68ms, Maximum = 68ms, Average = 68ms` How are you going to get sub 10ms with that? – starbolin Jun 05 '12 at 16:50
  • You might be interested in [Sync JS time between multiple devices](http://stackoverflow.com/q/10585910/1048572), which offers many solutions. – Bergi Jun 05 '12 at 16:57
  • @Bergi This is abou synchronization, but not with NTP – timaschew Jun 05 '12 at 17:04
  • @starbolin The error ist worst case is only half of the round trip time. Okay 10ms isn't possible. I want only the most precision value. – timaschew Jun 05 '12 at 21:22
  • No, the uncertainty, without clock disciplining, is the difference between the best case one way time and the worst case one-way time. Which may, at times, be more than the average round trip time. Worst case time is not garanteed in a best-effort network ( TCP/IP ). – starbolin Jun 06 '12 at 03:31

1 Answers1

1

An NTP client servos the computer's own internal clock for resolution. The client must estimate UDP round trip times and change the inernal clock rate ,slowly, to minimize the average error.

starbolin
  • 840
  • 5
  • 13
  • 1
    Okay, I found that JavaScript can not handle UDP requests, so there is no directly solution for it?! – timaschew Jun 05 '12 at 16:50
  • Nope. Not using NTP, at least. And definitely not in JavaScript, as that can't change the system clock. –  Jun 05 '12 at 21:44
  • 1
    @duskwuff I don't want to change the system time, I will work with the NTP offset. – timaschew Jun 05 '12 at 22:50
  • 2
    Rfc5905 - NTP is a server-to-server synchronization protocol not a time service. – starbolin Jun 06 '12 at 03:16
  • 1
    server-server you sure? because with android you can use NTP. An androi device act as a server? I don't understand why it should be a server. – timaschew Jun 07 '12 at 07:50