Panos_gr

hello all,

i have a client and a server application where the client sends gps coordinates to the server either via WiFi, or GSM (for now). I am trying to find which would be the best way to timestamp my packets so that the server would calculate the time difference between the time a packet was sent from the client and was received by the server.

if I use the usual DateTime.Now on the client it would not be accurate since the client would easily -and most probably- have different time from the server (the time difference might be negative!). I am not looking for the most accurate sollution down to the nanoseconds but a reasonable one ...

any ideas

many thanks!



Re: Smart Devices General time difference between client and server!

V1.0.0.0

You can use a same base (configurable) of time at both client and server. For example you could use GMT at both ends.





Re: Smart Devices General time difference between client and server!

Panos_gr

the problem is not the base, (e.g. GMT or UMT) but how can they be synchronized in the first place...





Re: Smart Devices General time difference between client and server!

V1.0.0.0

using a common base would automatically synchronize them.

e.g.

Suppose the client sends a packet at GMT time Tg1.

The server receives it at some time Ts.

You convert Ts to GMT time --> consider that Tg2.

Now when you take the difference Tg2 - Tg1, I suppose you would get the accurate value that you need.





Re: Smart Devices General time difference between client and server!

Panos_gr

hmm what i mean is how they can take an instance of GMT time that has the exact same time





Re: Smart Devices General time difference between client and server!

V1.0.0.0

what toolset are you using at the client and at the server to program the applications

the .NET FCL gives System.DateTime.UtcNow that might be helpful.

http://msdn2.microsoft.com/en-us/library/system.datetime.utcnow.aspx





Re: Smart Devices General time difference between client and server!

Panos_gr

hmm by the word toolset i guess that a reply like i am using .NET 2.0 framework on my server and .NET Compact framework 2.0 on my client would be an appropriate answer, right :-)

i see your point but this goes back to my initial point. Quoting from the link you gave me

"Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC). "

Thus, if my client decides that its clock should be 5 minutes ahead (so that he won't be late on his appointments;p) i would end up on the server's side receiving a packet created at a point in future !!! ...you see

ps. thanks a lot for replying.. any other ideas





Re: Smart Devices General time difference between client and server!

V1.0.0.0

could you embed locational (time zone) information in the packet or does the server already have that for each packet it receives from every device i.e. information about the time zone of the location from which the packet is coming





Re: Smart Devices General time difference between client and server!

Panos_gr

hmm i don't get exactly what do you mean.. i can know the timezone that my client is e.g i can know the time zone of the location from which the packet is coming but what difference does this make

e.g. yes i know that my server is at north uk and i am at south uk...so could you elaborate on what you have in mind...cause seems intresting;-P





Re: Smart Devices General time difference between client and server!

V1.0.0.0

Probably I was thinking on the wrong lines.... excuse me for that.

One more thing .... could you maintain your own clock on the client and synchronize it with the server time whenever your application starts I am not sure how much overhead would this be ....but just a thought....





Re: Smart Devices General time difference between client and server!

ScubaSteve20001

As the poster above mentioned, I think the only way to keep as accurate a time as possible with the server is to synchronize your devices clock with the server. So just set up a mechanism to get the UTC date from the server then P/Invoke into the devices 'SetSystemTime' function to set its time to that recieved by the server. Look on msdn for further details about the 'SetSystemTime' API.




Re: Smart Devices General time difference between client and server!

Panos_gr

well i have thought of that but it is way to difficult to be done once in a while... you don't know if the client runs out of batery and loose its time and many many others that are application orientedSad i was wishing that there would be an "object" from where i could get an instance of a time...from time to time;p

ps. thx for your ideas though.. i ll have to think more for an efficient solution...





Re: Smart Devices General time difference between client and server!

ScubaSteve20001

Why don't you just make it a requirement that before you ever send your gps coordinates that you get a timestamp from the server. Then you compare that time to the time on your device and if they vary, assume that the gps coordinates were taken with the old device time and add the difference of the times to the gps coordinate timestamps. That should work.

Or if you are just getting the timestamps of when you recieved the gps coordinates, if I recall correctly, you recieve a UTC timestamp with the NMEA fix data string from the gps reciever (assuming that, NMEA is the format you are recieving from the GPS reciever), so you could just use that.




Re: Smart Devices General time difference between client and server!

Panos_gr

hmm your ideas are really nice but the problems are the following :

the connectivity between the server and the client is really expensive and is not always available... so the client may end up sending the gps coordinates via Wifi (with a WLAN) or GSM or even GPRS(this hasn't been implemented yet).. so it is way to difficult to receive the timestamp from the server before he sends the packet...

this is a nice sollution..the clients can get the UTC timestamp from the satellites (you correcly recall;-)) but the server does not have any access to any satellites so that he could have his own timestamp and compare to the one being sent from the clients...

does the windows time service (i haven't used that before and i do now know if i can use it) have the same timestamp as satellites have