I'm writing a game server in Java. As common in game servers, I must take data received by one client and distribute it over the client's room (other clients). Currently, each client spawns its own thread and works on top of that. I'm having trouble, however, to define the inter-player relations. How do I control something like chat, where a message must be echo'ed to all the other players in the same room? I'm thinking in something like a message queue, where all threads would often look for messages and send them to its own client.
I'm also open to suggestions that would ditch multithreading at once, but I'm not familiar with NIO and the server is already written using plain Socket
s and Thread
s.
Summary: How do I make my clients (in threads) talk to each other? Or is there a better non-threaded alternative to this?