C++ – How to synchronize the clocks of two computers using C++

How to synchronize the clocks of two computers using C++… here is a solution to the problem.

How to synchronize the clocks of two computers using C++

I have two computers, A and B. I need to make sure they are exactly in sync with each other (within the range of ms). One computer is Windows Base and the other is Linux. They are directly connected to each other via Ethernet (the cable of one computer is connected to the other). I can write C/C++ code for each of them.

How can I get them in sync with each other y Note that neither Windows nor Linux is a real-time system, so you don’t know how long it takes for a packet sent over Ethernet to be received by the other party, so you can’t make it up. Since you need the precision of ms, this delay is important.

Is there any algorithm that can do this?

Is there any function in Windows/Linux that ensures that when you send data over Ethernet, it is immediately passed to the other end?

Solution

Synchronizing clocks between two machines is not an easy task.

One known method with falling precision is Marzullo’s Algorithm

Related Problems and Solutions