I'm trying to figure out how to create a Java based chat room. I have the following in mind but am stuck at the point where how do I broadcast to everyone in the chat room?
The following pseudo code:
Server sits in while loop listening for clients on a port
Clients connect to server, server creates a new thread for the client.
Within the new thread, there will be another 2 threads for incoming and outgoing msgs.
Now, this is the point where i'm not sure if it'll work or not.
Lets say a client sends a message in the chat room, now the server receives the message and must send the message back to everyone in the chat room. I'm not sure if this is possible or not, but I was thinking the server can keep a link list of all clients and just do a output to them all in the main server program in which created all the threads.
Would this be the right way of implementing a chat room and are there any simpler implementations?
Thanks
- hito
The following pseudo code:
Server sits in while loop listening for clients on a port
Clients connect to server, server creates a new thread for the client.
Within the new thread, there will be another 2 threads for incoming and outgoing msgs.
Now, this is the point where i'm not sure if it'll work or not.
Lets say a client sends a message in the chat room, now the server receives the message and must send the message back to everyone in the chat room. I'm not sure if this is possible or not, but I was thinking the server can keep a link list of all clients and just do a output to them all in the main server program in which created all the threads.
Would this be the right way of implementing a chat room and are there any simpler implementations?
Thanks
- hito