network time synchronisation in java
Hi everyone! I hope someone can help me with this problem.
I need to synchronize two network clients in time so that they can execute a command at an exact point in time.
* FIRST: An algorithmic approach
I have tried to solve this problem by sending packets between the two clients, but it seems to be theoretically impossible. Anyone with a solution here.
* SECOND: Using network time protocol (in java?)
The second approach I come up with is using some sort of network time protocol. I have no experience of this and can not find anything of employing it with javas standard packets (I donīt want to use third party packets in the first run). Anyone with some experience on this issue.
I use the udp protocol for data transfer between the clients and need an accurancy of <= 10 ms. Can it be achieved (with java)?
/Anders Persson (bossebo)
what you propose is nearly impossible in any language.. you can get close but true synchrony will be near impossible, as the computer clocks are not guaranteed to be in sync even 1 second after true-syncronisation
can you tell a little more about why you need this precision
Well, its a real time application between network-clients and therefore synchronisation in time could help compensate for absolute and relative network-latencies.
It is not a problem for me to send sync information every second or less...
as the computer clocks are not guaranteed to be in sync even 1 second after true-syncronisation
I will try to rephrase the question:
Is there any way to synchronize two clients that are better than do a "ping" with my present time, and inform the client that his time should be mySentTime+(ping/2) when the ping reached him. That is, we are asuming that the ping package took equal amount of time to reach the client as to get back.
resolution of latency is generally not considered; it is left to the user to compensate.. experiments have been attempted in games like quake, but it becomes irritating after a ertain level of compensation.. it is perfectly feasible for a server to remember where players were up to 10 seconds ago, but how many people would appreciate running down a corridor then suddenly dying because a modem user with a lag of 800ms, shot them 800ms ago..
what if they killed someone else in the meantime?
with latency, it a case of you-snooze-you-lose..
however, your method is the current accepted method of synchronising two PCs. for more info and algorithms, look up how NTP works..
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center