The infinite loops role is to send out a keep alive signal on the socket to all the clients every X seconds.
One simple mechanism would be to have the child process (or thread) connect back to the listening socket and send a message every X seconds. Your existing code without modification would forward these to each of the clients as any other message. Though you might want to avoid sending stuff to the keep-alive client. Once you start discriminating about what messages you forward to what clients, the keep-alive just gets forward to all clients (except it's originator) as now.
Of course, the next step is likely to be to only send keep-alive messages to those clients that you haven't sent any message to (and perhaps, received a message from) for the last X seconds. It's at this point that the thread would come into it's own, as you can then use a shared hash to record the last time a message was sent to each client.
The keep-alive thread then wakes up every X/n (where n depends upon the resolution you require), scans the shared hash, and sends keep-alive messages, with a client identifier parameter, for each client who's time falls due within the next X/n period. Your main select loop will receive and forward these messages in the normal way.
In reply to Re: Printing to all clients on a socket from a child process
by BrowserUk
in thread Printing to all clients on a socket from a child process
by Fredde87
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |