I am trying to create a sort of chat program as an exercise. I have an example from a book showing how to create a connectionless server and a connectionless client with internet sockets, but I want to be able to connect with multiple clients and do it so that any client can write at any time and the message is sent to all other clients.
I've tried connecting with two clients to the same server, and the result is that the server gets messages from both clients, but the clients only get every other message from the server (i.e. the server seems to send to the client that sent a message last).
Anyone who knows how to fix this? Do I need one thread/process per client and have some sort of interprocess communication between the server threads? Or maybe multiple sockets?
I've also found that part of the solution is something called non-blocking io which is also in this book, but I don't have the include "filio.h" which might be a UNIX-specific include. Anyone who knows what the equivalent is in linux (Xubuntu 8.04)?