• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronizing between two PC`s

 
Redan Hassoun
Greenhorn
Posts: 28
Android AngularJS Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need help in a java application which should start a sound recording in two PC`s in parallel.
I have a server which is connected to two clients using Socket connection - each of this three components is running on a separate machine, and they are all connected to the same WI-FI.
The server should send a "Start Recording" command to both of the clients at the same time.
A 1 millisecond delay is considered bad - I want the two PC`s to start recording precisely at the same time .

What is the best way to implement this ?
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't.
 
Henry Wong
author
Sheriff
Posts: 22518
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not completely impossible ... just maybe impossible...

First, you need to determine the network lag. And since the different machines clocks are not in synch, you need to determine it via a ping pong protocol. Send the current time to the other machine, which will quickly reflect it back, and upon return, the lag is the time difference divided by two.

Second, you need to determine the accuracy of the measurements. This means that you need to do many ping pongs calls, and measure the standard deviations.

And third, unfortunately, if the standard deviation is over 1 ms, then it has to be declared impossible...


Once you have the network lags, you can probably work out a protocol to sync the clocks, and to execute in parallel, which again, must be done within the acceptable deviation. This, of course, brings up the final point. Can you guarantee to do this? The answer is "no". To "guarantee" that it would work, implies that there will no outliers, which of course, always exists doing stuff like this.

Henry
 
Ron McLeod
Saloon Keeper
Posts: 1263
131
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Redan Hassoun wrote:.. A 1 millisecond delay is considered bad - I want the two PC`s to start recording precisely at the same time ..

1 millisecond latency through WiFi is not going to happen.

However, if you want to preserve the timing of the media (sound recording) from the source, across the network, to the receivers/recorders, independent of any network jitter or receiver processing delays, then you might want to wrap your media with something like Real-time Transport Protocol. With RTP, synchronization of media samples is maintained with a timestamp set at the source, and a sequence number is provided to detect lost or out-of-sequence samples.

Also, since you have multiple receivers, you might want to broadcast or multicast you media rather than sending the same media in multiple streams.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!