I have wrote a server program that can handle multiple client by using fork(). I have a signal handler, error checking where needed, and everything works correctly. I have it set up where if a client enter ‘quit’, the server should stop accepting connections, let the opened clients finish their communication, and close once all clients are closed. To do this, whenever ‘quit’ is entered, I have an int flag that is set to 0. Since the variables in each child process are only for that process, and do not affect the other child processes or the parent process, I can’t keep track of when the flag is set to 0. In my signal handler I am checking
if( count == 0 && flag == 0)
//close server and exit program
count is the number of clients opened which after they are all closed will obviously be zero ( this has been error checked to make sure it is correct). Does anyone know of a way I can create flag that can be set inside one client, and have that same value for every client? If that makes sense.. I am coding in C by the way.
You need to implement a single server for everyone to speak to, he will broadcast back to all the clients to update them with the client count, but in essence without a lot of complication to speak and keep track of all the other clients is a bit of a challenge.
This would also be a place to route and traffic messages between different clients.
Hopefully this shines some light.