🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Exact Syncing

Started by
28 comments, last by SaltySnacks 23 years, 7 months ago
I have a program I''m working on. It is going to being a client/server app. I need to have all the clients to be synced up exactly so that when a button is pressed, I can determine who clicked it first. Also I need to be able to start animations on all the clients at the exact same time. Anyone have any ideas as to how i would acheive this? thanks, SaltySnacks
Advertisement
Won''t happen in this lifetime. There will always be at least some lag in everything you do... be it 8ms on a 100Mbit Ethernet connection or 8 seconds on a 300 baud modem. Trying to get rid of it will most likely result in the loss of your sanity.

The best thing to do is to just try and minimize the effect of lag on your application.
He didn''t say it needed to be free-floating time

Sync time (ping->pong) and lock frames on the clients. During frame updates you send the time the command was issued with it and you could determine who clicked what within +/- 5us using QueryPerformanceCounter(), or within +/-10ms using clock().

You can''t ever have things sync to the exact same time, but pretty close (5us!).

...
Unrelated Fluff:
...
Also no latency connections could be possible one day:
Experiment:
Split a photon with a prism directly between Paris & Berlin
Send the first half photon towards Paris
Send the second half towards Berlin
Manipulate the photon half when it arrives in Paris.
The second half mystically undergoes the manipulation in Berlin.

I don''t think those were the cities the were used, but you get the idea... You could instantly send data to the moon or to Mars or wherever. But the source needs to be close to the center point, split a beam strong enough to reach both destinations, and accurately aim the beam to hit both receiving ends.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Magmai, consider this:

1) A Server located in L.A.
2) A Client located in New York
3) Client connects to the Server and the ping->pong method is used to determine round trip time.

Now, let''s just suppose this is a private network and not the internet. Let''s say that they are connected via a T1 (full duplex). What happens if someone in the client''s office is downloading something from a different site in LA? There is very little New York->LA traffic, but quite a lot of LA->New York traffic all on that single T1.

In that case, the trip from New York->LA could take 5ms, but the return trip could take 5 seconds if we want to play devils advocate. So the round trip time would be 5.005 seconds, and splitting it in half would indicate that the trip from New York->LA took 2.0025 seconds, when really it only took .005.

Factor in that the ''extra'' network usage could start / stop at any given time, and there is really no way to accurately guage a 1-way trip, especially not down to 5us.

That make sense to anyone but me, or should I clarify?
In my application, however, the server and the all the clients will be within 1 mile of each other, and everyone is using a T1 connection. Does this open up any possible solutions? Also, it doesn''t have to be EXACT, but as long as i can tell who clicked the button first, thats all i care about.

thanks.
Yeah I see what you''re saying. It''s really bad if you''re time-sync is wrong.

If the ping->pong trip time is over 500 milliseconds you should probably reject it. You could do several pings over a few seconds and average....


Maybe you could time-sync to one of those internet connected atomic clocks. That supposedly gets you within 10ms or so.


And it really is possible that two people will click the button at the same time, and quite likely that you get two people clicking the button within your time tolerance.

...
no wait, it doesn''t matter how long it takes or even if it''s different times on the ping vs the pong

//psuedo code
NY->ping(LA, clock())
LA->RecievePing{LA->pong(NY, clock(), ping)}
NY->ReceivePong
{
now = clock();
triptime = now - pong.ping.clock;
offset_to_server = (pong.clock - triptime) - now;
}

NY->SendData(data, clock()+offset_to_server)

now whenever you send data to the server, send a timesync stamp
and it will be sycronized to the server''s clock(), and it doesn''t matter how long it takes to get there.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
hey thanks...that looks like it might work. i will look into this next week sometime...

thanks again,
saltysnacks
Right Magmai, but do a little test sometime... find a really busy server somewhere, www.yahoo.com? set up ping to continually ping it once every second for i dunno, 5 minutes?

Then tell me what your min / max / average ping times are and what the difference between them is. =)

I like your timestamp method, but you''d have to make sure to re-perform the ping time every 10-15 seconds to account for lag spikes etc...
no lag spikes don''t matter
its doesn''t matter how long it takes or how much it varies.

You have to send the timestamp with every packet though, in server clock ticks. But once you have calculated your offset from the server you never need to ping->pong again - unless the server crashes or you reboot your computer
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
But there''s no way to reliably get synchronized with the server to begin with. Your margin of error is the round trip time.

This topic is closed to new replies.

Advertisement