Question

By writing simple System.out.println() on server side, the message goes to all clients. But is there a way to make one client's address embedded to a java function which recognize that the server is sending a message to this specific client?

Was it helpful?

Solution

This probably requires a bit more information to be specific, but I'll try and run with it.

So if you have a server that maintains a list of clients that are connected, you could ideally tag each one with some type of ID when they make a connection into the server.

For example lets say you had a server that managed some kind of data and two types of clients could connect: Managers and Customers.

Now when a client connects you can setup the server so that it asks the user which they are and verify with a login maybe. Continuing from that you could place all of the types into unique lists and then broadcast to those lists separately.

Additionally since you can control the server and client application. You could generate a random ID number/tag/something for each user that connects and store that in a list. Then should the server want to message a unique client you just have to search the list(or hashmap) for that users socket/connection and broadcast to them.

I know this answer seems a bit vague but the information provided felt that way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top