Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronize time/events between game (MMORPG) client and server?

I am currently working with Java server side and as3 client side. I'm wondering if there is a silver bullet out there for synchronizing the clock between them. Between variable latency and variable clock speeds it seems like each packet would need a timestamp.

Thanks!

like image 248
jestro Avatar asked Apr 06 '12 04:04

jestro


1 Answers

This is just off the top of my head, without any code.

  1. Put code in the server and client to send and receive a ping.
  2. Send a ping from the client to the server every time the client connects.
  3. Record the current time as te send time.
  4. When the client receives the ping, record the current time at the receive time.
  5. Get the time delay by subtracting the receive time by the send time and divide it by 2.
  6. Have the server send the current time to the client.
  7. Subtract the time difference from the time server sent.
  8. Set the client time to the time from step 6.

I'm not sure if this will work 100% accurately, but I hope this helps!

like image 162
Cin316 Avatar answered Oct 02 '22 00:10

Cin316