I am writing a program that uses sockets and forking. What I'm having it do is receive a message on one of the child processes, and then that message should be distributed to the other child processes. You can think of it like a chat server as that is the most similar concept.
I'm at a point where I'm wondering "how should I implement" - specifically the piece where data comes into the read buffer for a child process, and how it is then transmitted from each of the child processes to their connected peers.
My pseudo code is this...
setup socket parameters
accept call (blocking)
listen for messages
when i get a message, send to other child processes
close file descriptor
There's the RIGHT way to do it (which seems like a lot of work, and I want to PROTOTYPE this first) which is to build a dispatch-type of service, which learns about FDs and other metainformation from the child processes when spawned. This dispatch could act as a registrar, and add/remove child processes as they are born/die.
The dispatch could also become a messaging relay, i.e. a child process could say "send my peers this message", since it has this metadata.
As per the above, writing a dispatch is the right way but will take a painfully long time. Anyone know of a simple way to do this using C?