Network counter synchronization

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.

+4
source share
2 answers

An obvious resource is NTP, which is documented, for example, at http://www.eecis.udel.edu/~mills/ntp.html and with links. It mainly uses timestamps to adjust the frequency with which the local clock works. The protocol has existed for many years and is the subject of continuous research - I do not see a single package of slides that immediately makes it clear how this works. You might be better off finding out if an NTP implementation is already available than trying and reimplementing it yourself.

It appears (for example, from search) that there is a small industry of people working with time synchronization algorithms, especially in the context of wireless sensor networks. One transition point, in addition to search queries, is a review article at http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.85.2012 - Time synchronization in sensor networks: survey (2004)

+1
source

If you use these counters to order events in the system, you should look at the vector clock or Lamp timestamps .

+1
source

Source: https://habr.com/ru/post/1436268/


All Articles