Sign in to follow this  
dongzhe

how to synchonize the time between client and server

Recommended Posts

dongzhe    114
Hi all I am new in online game. just a question, have read some articles about prediction and latency. they all mentioned that send the time(t0) that action was performed to the server from client. latency time t1, server process the message at time t2. client pos = v*(t2-t0+t1). My Question is how to synchonize the time between client and server?????

Share this post


Link to post
Share on other sites
hplus0603    11347
Here's the simplest method, which works well enough:
Put a timestamp in each packet that the server sends to the client.
The client records the client time at which the server packet was received.
This gives the client an offset: server time at client clock.
Because of jitter, that offset will vary slightly over time, so you typically want to use a leaky integrator (smoothing average) for this offset over time.
Additionally, if you measure round trip, you may want to add half of the round trip to the server time estimate.

Note that time is not so much about exact synchronization (a la NTP); instead, it's about making sure that you order events along some monotonically increasing timeline.

Share this post


Link to post
Share on other sites
dongzhe    114
thanks very much mate!


Quote:
[i]Additionally, if you measure round trip, you may want to add half of the round trip to the server time estimate..


can you explain more about it? what do you mean by that?

Quote:

Note that time is not so much about exact synchronization (a la NTP); instead, it's about making sure that you order events along some monotonically increasing timeline.


example?

Share this post


Link to post
Share on other sites
kyoryu    224
It's essentially impossible to have your client and server perfectly synced. So don't even bother.

What's important is that they have some common idea of time that's at least relatively in sync. So that the server doesn't just say "spawn rocket now," but rather says "a rocket was spawned at time t at this location."

By having a common understanding of time, and referring to events as happening at a particular time, the separate simulations on the client and server can remain relatively in sync, and then be corrected as you go on.

Share this post


Link to post
Share on other sites
dongzhe    114
i seem understand the theory.

if imagine the client is in different time zone, let's say 9 am, but server is now 11pm, how to make they to have same heart beat??

can anyone give me a logic, like skeleton code.

thanks

Share this post


Link to post
Share on other sites
Kylotan    9860
All that matters is relative time. Their own local time is irrelevant. You can measure time relative to the start of the game, or a previous message.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this