[ENet-discuss] Time synchronization client/server/clientcommunication.

Ruud van Gaal ruud at racer.nl
Tue Mar 2 12:40:14 PST 2010


Hi Alexander,

Give each client and server their own timer.
Then use for example peer->roundTripTime for the ping time.

So:
- client A sends 'player pos is XYZ at time T'
- server receives packet, calculates server time by:
     serverTime=packet.T+clientA.roundTripTime (/2?)
- server sends on packet using serverTime to client B, C etc

In my case, each client knows its own ping time to the server. By using
server time where possible, it's easier to convert to local client time when
needed. I use my own pings here & there to get a quicker roundTripTime than
ENet's peer->roundTripTime though; that one seems to stabilize less quickly.

The ping command just does this:
- server sends out ping with serverTime
- client responds with serverTime and localClientTime

This way I have time offsets for each client on the server.

Hope that helps a bit; more than 1 timing algorithm will work.

Cheers,
Ruud

> -----Oorspronkelijk bericht-----
> Van: enet-discuss-bounces at cubik.org 
> [mailto:enet-discuss-bounces at cubik.org] Namens Alexander Shyrokov
> Verzonden: Tuesday, March 02, 2010 23:42
> Aan: enet-discuss at cubik.org
> Onderwerp: [ENet-discuss] Time synchronization 
> client/server/clientcommunication.
> 
> Hello,
> 
> I have multiple clients connected to the server. The server 
> echos the received data from any single client to the rest of 
> the clients. I would like to know the time when a packet is 
> sent by the original client. How do I do that? It is clearly 
> a very common situation in games. I get position of a player 
> with the velocity. Given that some time elapsed since the 
> packet was sent I can estimate current position by using 
> elapsed time and the velocity to get the offset.
> 
> To simplify, let's take an example: Client A sends a packet 
> to the server, server then sends this packet to the Client B. 
> Client B needs to know who many seconds ago Client A sent the packet.
> 
> There are two stages: first the server needs to know how many 
> seconds ago Client A sent the packet, let's call it DelayA; 
> second Client B needs to know how many seconds ago the server 
> sent the packet (DelayB), as well, as DelayA.
> 
> I assume I can use round trip delay to get both delays. The 
> only issue is that I am using unreliable packets, meaning 
> that I do not get acknowledgments. This means I do not get 
> round trip delays. Is there a way around it?
> 
> What I plan to do is, to open the communications on three channels. 
> Channel 0 will be used to send unreliable packets (the actual data). 
> Channel 1 will be used to estimate round trip delays by 
> sending reliable packets from the server to every client 
> every N seconds. Server then sends information about round 
> trip delays about every client to every other client on 
> Channel 2, so that every client could estimate the delay for 
> messages that are received. Of course, I could load the 
> server by modifying actual packets that are transmitted to 
> the clients to include DelayA, and DelayB will be measured 
> directly by the clients.
> 
> Any suggestions are welcome. Maybe there is already existing 
> implementation to this situation?
> 
> Thanks a lot,
> Alexander
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss



More information about the ENet-discuss mailing list