I'm trying to create a server/client which will be similar to IRC. I want the users to have nick names which they can register. Then the ability for them to join channels (or chatrooms).
What would be the best way to create a server/client with multiple chatrooms?
Should I send which channel to display the message to the server, then let it give it give it to a channel thread which will send the message to all the sockets connected to that channel. Or should I make it so that the user has a direct connection to each channel?
Also how can I associate nicks? Should I also send the name of the person who is sending the message?
How can I associate a socket with a nickname?
I'd have a separate thread for every connected socket, storing messages in some kind of queue. Then a separate thread sends the incoming messages asynchronously to all other connected sockets.
- Separate ServerSocket and port for each room, plus directory service
- Single ServerSocket and Tag each message with the destination room
Both methods, maintain a list of all sockets in a room. For nicnames, use a similar message tag. Name could be stored in a Map<Socket, String>, Thread.getName(), etc.