larstoc
larstoc

Reputation: 55

How to synchronize timers of two programs

I am making an application where I have a client and a server. The client will send some coordinates to the server which will use those to move a robot. What I want is to synchronize the timers, used for time stamping log data, so that I can compare the input vs output. The communication is done through TCP/IP, and the client is done in C++ while the Server is in RAPID (ABB robotic programming language). My problem is that the timers are not synched properly.

Right Now the timers start when the connection between the two is established:

Server side: ListenForConnection; startTimer;

Client side: connectToServer; startTimer;

This does not work. Is there a technique to ensure that the timers are synchronized?

NB: The server can only be connected through LAN.

Upvotes: 0

Views: 1713

Answers (1)

GreenAsJade
GreenAsJade

Reputation: 14685

You need a protocol between client and server to pass the timestamp.

Right now, presumably you have a protocol for sending coordinates. You need to extend that somehow to allow one side to send timer information to the other side.

The easiest is if you have two way communication capability. In that case, the client does

  1. Connect to server
  2. Keep asking until the server is there
  3. Server says "yes I'm here, the time is 1:00"
  4. The client starts sending coords

If the server has no way to send to the client, then the client needs to send a timestamp from time to time, which the server recognises as being a time, not a coordinate. The two will not be synched until this happens the first time.

Upvotes: 1

Related Questions