Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Send messages to clients selectively?

 
Yingie Pitts
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Ess
Bartender
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you share some more information? How you are keeping track of client connections? Are you using java.net.MulticastSocket?
 
Yingie Pitts
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic