aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Send messages to clients selectively? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Send messages to clients selectively?" Watch "Send messages to clients selectively?" New topic
Author

Send messages to clients selectively?

Yingie Pitts
Ranch Hand

Joined: Oct 10, 2002
Posts: 37
I used BufferedWriter.flush() to send clients messages that the server read in from one client. But this sends the message to every socket-connected client. How can I send a message to a particular client(s)? Help, please.


"To err is human, but to really foul things up you need a computer." Paul Ehrlich.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Can you share some more information? How you are keeping track of client connections? Are you using java.net.MulticastSocket?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Yingie Pitts
Ranch Hand

Joined: Oct 10, 2002
Posts: 37
No I am not using java.net.MulticastSocket. I am keeping an ArrayList of client socket objects on the server socket. Everytime a client logs in, the client notify the server to add one more client connection into the ArrayList. This is how I keep tract of my client connections.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

OK, so at some point you must iterate through this ArrayList, opening an OutputStream (and BufferedOutputStream) on each, and writing the data to each socket in turn, right?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Send messages to clients selectively?