Jump to content

  • Log In with Google      Sign In   
  • Create Account

Server/Client Time Synchronization?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 3TATUK2   Members   -  Reputation: 730

Like
0Likes
Like

Posted 12 October 2013 - 02:41 PM

How can I properly synchronize time between client/server and all other clients?

 

For example, say I have a server broadcast command to all clients like "start match".

 

Obviously, you want all clients to start at the same time... But if you simply, say, start the match on the client... 10 seconds after receiving the server command... There will be variation between clients of when they receive the command based on how good their connection is and how many times the packet may be lost or have to be resent



Sponsor:

#2 dklompmaker   Members   -  Reputation: 106

Like
1Likes
Like

Posted 12 October 2013 - 07:37 PM

Typically you would send a ping message every n-seconds. When the server receives the packet, it will impart the server time (in tick form) and send a response back to the client. The client would then know the following:

 

1: The time the packet was created by the client in ticks

2: The time the server received the packet

3: The time the client received the packet

 

Then using that information you can determine the latency between the client and the server.

 

When the client receives the ping message they can get the server time (from the message), then add the latency to get "actual" server time.

 

You could then store that initial server time, and client / server time difference into a variable on the client. Then using a property automatically get the "actual" server time by then adding the average latency.

 

(not real code)

public DateTime serverTime
{
   get {
     return clientTime + serverDifference;
   }
}

Hopefully this gives you an idea on how to get started doing this!



#3 hplus0603   Moderators   -  Reputation: 5693

Like
2Likes
Like

Posted 12 October 2013 - 09:07 PM

You cannot be 100% "in sync" because of the law of relativity. Also, because of network lag.

That doesn't matter. All you need is for events to happen in the same order and at the same speed on all machines.


Edited by hplus0603, 12 October 2013 - 09:07 PM.

enum Bool { True, False, FileNotFound };

#4 wodinoneeye   Members   -  Reputation: 876

Like
0Likes
Like

Posted 14 October 2013 - 11:53 PM

I did something like this with my own reliable delivery protocol built ontop of UDP.   The ping mechanism was at a low level built right into the network packet processing thread (client and server).   An incoming ping was processed immediately and the reply (pong?) pushed out the socket immediately to eliminate queueing delays.    The round trip time was tracked for the connection to be used for various things like game clock sync adjustments and also for signaling the game's Application level of slowdowns in communications (so compensation/adjustment could be made at that level to game traffic being generated - like priority near details and slowing updates of further away details).

 

That project was for a large scale server cluster (lots of processing nodes for one game world)  with ALOT of packet traffic within the server itself as well as out to multiple clients.    That meant that a slowdown to the clients was signalled around the cluster (more low level priority signalling).   Various other special traffic was made to do keep-alives and low level background file transfers.


--------------------------------------------Ratings are Opinion, not Fact




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS