This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 8834
    
    7

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: 8834
    
    7

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?
 
Don't get me started about those stupid light bulbs.
 
subject: Send messages to clients selectively?
 
Similar Threads
looking for design pattern for passing data to session bean
serverSocket
Pls anyone answer this, its urgent
How to break blocked write operation???
Implementing a message broadcast server using servlets