DEV Community

Discussion on: Synchronize program start over network

Collapse
 
madhadron profile image
Fred Ross

You're going to open a socket to somewhere. There has to be some means of communication. If it's a throwaway and you don't need synchronization better than a few hundred milliseconds, and it's only these two machines, call one of them the master, one of them the minion, and write a pair of bash scripts.

On the master, the bash script runs ncat or netcat listening for a connection a port. As soon as it receives the connection and netcat exits, run omxplayer.

On the minion, use ncat or netcat to connect to the master, and once it exits, run omxplayer.

This is brittle, it can't give you better precision, if there are errors it has to be reset by hand, but if you really just need this to happen, it will work.

If it is likely to grow to other machines or you need better precision then you need to do something more sophisticated. One of my usual tricks for an architecture is to replace any fixed number of things with an arbitrary number that might be very large and think about how to make it work. If I needed higher precision and many machines synchronized, I would use something like Zookeeper or etcd (hereafter the coordinator). Make sure you have NTP synchronizing the time to the necessary precision (or add atomic clocks to the machine if you need really high precision). Each of the minions connects to coordinator and elects a master, starts the video paused, then waits on a shared location in the coordinator to have a value set. The master picks a timestamp a little bit in future and sets it into that location. Each machine is notified of the new value, loops until it reaches that timestamp, and starts the video.

Collapse
 
computersmiths profile image
ComputerSmiths

Ah, ncat would have worked, thanks! Shouldn't need any more than the two machines, it's a couple of Raspberry Pis playing videos on a pair of "Lady Gaga Glasses", so unless she grows a third eye, I should be good. 8*)

Thanks again!