Synchronize Clocks
BlitzPlus Forums/BlitzPlus Programming/Synchronize Clocks
| ||
Is there any way to synchronize a timer over a network? It needs to keep track of a millisecond and it needs to be PERFECT. |
| ||
Probably not. Why does anything have to be PERFECT anyways? |
| ||
You can usually get a ~5ms difference by calculating the lag between client and server and adjusting the clock. Client: PING Server: PONG Client calculates time to get PONG Client: TIME Server: ##### Client stores the difference between its value of MilliSecs() and the time given by the server, and add half of the lag calculated before to it. Client: DIFF ##### (giving it's own calculation of the time) Server: ##### (difference between given time and server's time) The last two commands should be runned from time to time (each minute for example). Remember to remove half of the answer time to the difference. *Usually* the upload and download lag are the same on the client. However if the client is saturating its upload (p2p software) it may become hard to evaluate the exact time lost in packet transmission. This solution should take care of the other cases :) |
| ||
There may be an online service providing accurate timing that you may use. |