Search code examples
linuxsocketspthreads

How can I send a command to all connected clients from a putty terminal window?


I have 4 robots which have a linux OS and are currently communicating between each other using the client-server model. The server (leader robot) creates a thread for each client that connects to it.

I however need a 'kill switch' to stop the robots all at once. I have a function that will stop the robots however I need a method by which I send this command (or a message of some sort) to all the connected clients at the same time.


Solution

  • Human reaction time is going to be about 250ms by the time you see something wrong and then press 'enter' to stop. You could send one message to the leader and have it shutdown each of its clients, then shutdown itself.

    For a 'kill switch', I'd suggest the leader send 'keep alive' messages to the clients. The clients would then shutdown automatically (watchdog timer), even if all communication is lost.

    If it was really critical, you could have the leader also need constant data from the putty terminal (hold down a key). Once the data stops (release the key) it will stop, and its clients would also stop.