This week's giveaway is in the Java in General forum.
We're giving away four copies of Java Challengers and have Rafael del Nero on-line!
See this thread for details.
Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Creating a list of clients connected to server?

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
Im new to this Java ranch, so if this is repeating something I havent seen, I apologise!
Ok, my question is, can anyone tell me how to create a list of clients port and InetAddress details as they connect to the server socket.
I need to do this so that I can use the details to send messages back to all the clients.
(Im writing a client server chat program where one message from one client is displayed to all the other clients)
I have a thread that generates a new socket and I try to push these into a stack, which i then pop off to send a message back.
It works, but it seems I can only push one port on, ie a new stack is also generated everytime a socket is..
pleeeease help. Its driving me nuts! (and my family...!)
Thank you for any help offered
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what you can do is make a Vector object and keep on adding the chatclient object containing all relevant information about its socket and then send the message that arrives on the server to all the clients connected, by first getting an enumeration object from the vector and using while loop as follows
Socket client=(Socket)enum.nextElement();
PrintStream ps=new PrintStream(client.getOutputStream());
the complete set of classes as per my chat program should be as follows.
ChatServer()//multithreaded, so that it runs a seperate thread for each client logged in.
SocketClient() extends Socket
//this class must also store clients name and if necessary its serversocket if your chat program is also capable of sending a personal message.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic