calvinfo / socket-ntp

NTP Sync using Socket.io
42 stars 6 forks source link

Handling clock differences #1

Closed ilikejames closed 10 years ago

ilikejames commented 11 years ago

When there is clock difference between the client server, the offset is wrong.

This can be tested by changing the lib/ntp.js ntp:server_sync to:

socket.emit('ntp:server_sync', { t1     : Date.now() + 8000 /* clock 8 seconds a head from client */,
                                 t0     : data.t0 });

The proposed change is to update the client js file so that the diff is calculated by:

var diff = Date.now() - data.t1 + ((Date.now() - data.t0)/2);