Brann
Brann

Reputation: 32376

How do you compute the client/server timegap?

I'm developing a client/server software, and I'm searching the best way to keep my client clocks in sync with the server clock.

Of course, I can't use NTP because I don't want to touch the system clock. I'm just trying to compute a timegap so that I can add it to every single datetime received from the server to convert it into a 'local time'

What I do for know is that :

This works great when network lag is constant (read "my LAN"...)

Unfortunately, I want my software to work on the Internet, and even on mobile clients, for which I've witnessed lag variations up to 1 minute.

For the software I'm working on, such a lag is not acceptable.

What would be a good strategy to compute the client/server timegap?


Last thing : I can send messages in both way (client to server AND server to client)

It's probably irrelevant, but the technology behind this is a .net WCF client using an httpbinding with some polling

Upvotes: 1

Views: 430

Answers (2)

innaM
innaM

Reputation: 47829

Why can't you use NTP? Of course the default thing for ntp is to set the system time, but that is not obligatory:

$ ntpdate -q ntp.ubuntu.com
server 91.189.94.4, stratum 2, offset -0.102597, delay 0.05426
 2 Mar 11:44:36 ntpdate[12239]: adjust time server 91.189.94.4 offset -0.102597 sec

Upvotes: 1

Ikke
Ikke

Reputation: 101231

You could ping the server on regular intervals to calculate the lag. I don't think you can get really close over the internet.

Upvotes: 0

Related Questions