Skip to main content
gamedev.net
🔒 Locked

Client/Server time sync

Started by KevArnold 0 replies 1.2k views
Original Post
KevArnold
KevArnold
I am working on adding network multiplayer to a simple 2d game I have created.

Currently I number all packets sent between the client and server. If we've received a more recent packet we dump the one we just received otherwise we analyze it. The problem is how do I know if a packet is old and because of lag I'm just receiving it? Is this something I should not be worried about because if I don't receive packets for about 1 second then I can start to just think the client is lost?

Up until this point I have not seen a need to know the actual time of a packet in relation to server time or vice verse but wondering if thats because I'm doing something wrong. Is there usually a time associated with a game state packet or is order all that matters?
hplus0603
hplus0603
In general, if you have "game steps" that advance at a given rate (say, 60 steps a second or whatever), then the machines will synchronize step numbers, rather than time. Typically, you have some pipeline of step divergence allowed -- say, in this case, you can't advance to step N unless you've received data for step (N-30) from the other end.

When one machine has a temporary lag spike, the other machine will stop receiving packets for newer steps, and probably end up stalling until the laggy machine catches up.

If you don't receive any data for some time (a second, three seconds, whatever), then consider the other end lost/disconnected.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.