I have two computers that can talk to each other over a serial connection. The connection is wireless. There is a variable that changes the delay in the exchange of data between the two systems. On both systems, I have a runtime counter that increments by 1 every ms. They start immediately after launching the applications. Let's say each computer starts at a different time. How can I synchronize the counters using a serial connection, so that systemA.counter will be equal to systemB.counter and so that both counters increase at the same time (or as close as possible).
Ideally, after synchronization, the counters will drift only slowly, so that every 3 or 4 thousand Incas I could re-synchronize.
I am looking for good resources on the topic, examples of algorithms, sample code (c / C ++), anything to point me in the right direction.
Update
This is a closed system, not the Internet. In all senses and purposes, there is no real protocol, in addition, and open a serial line wirelessly. This link is currently bluetooth, but I think by moving it to ZigBee Mesh. There are currently 2 nodes, but if I have 30 nodes that run the same application, I would like all of them to sync. There is no client / server designation, but only a few devices working with the same program using a counter. I do not have access to anything like that, only this counter, which is incremented once every millisecond and any algorithm that I can set.
As soon as I can get this work, I would like to create a forecasting and comparison system, but to determine the distances between nodes I need to synchronize synchronization on devices.
source share