Malii
Malii

Reputation: 448

Java Multi-threaded server communicates to individual clients but not to all at the same time

I've coded a multithreaded server and it can handle many clients connecting at once. The only issue is, it only communicates with that specific client. Here is an example of what I'm trying to achieve: Client -> Server -> Client + Other Clients. However what I currently have is: Client -> Server -> Client

I know I have to store the data of the other clients on each specific client, but the problem is I don't know what the best way of doing this would be. Currently each client uses a string tokenizer and stores information about itself.

What would be the best way to send the information about other clients and the best way of storing it client side?

Thanks.

Upvotes: 1

Views: 295

Answers (1)

androidu
androidu

Reputation: 4728

You can use a message queue like in this example http://inetjava.sourceforge.net/lectures/part1_sockets/InetJava-1.9-Chat-Client-Server-Example.html

search for sendMessageToAllClients(String aMessage)

Also this example might be just what you need, a multi threaded server-client chat

Upvotes: 2

Related Questions