Results 1 to 3 of 3
  1. #1
    kathleenr is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default Chat program: how server distinguishes each client connected to it

    My task is to make a conference chat program with GUI wherein several clients may connect to the server.

    I'm just starting to develop my code and I'm stuck with these problems:

    One client sends a message to the server by pushing the button 'SEND'. The task of the server is to send this message to all clients connected to it.

    Each of the clients has a name (i.e. Client1, Client2). How will the server know which of the clients sent a message because the server needs to send this message to the clients:
    (for example Client1 was the one who sent the message)

    Java Code:
    Client1: Hello!

    Is there a way for the server to distinguish between the sockets connected to it, send messages to all the sockets connected to it, and choose a particular socket to send a message?

    Thanks for the future help! :)
    Last edited by kathleenr; 12-23-2008 at 04:54 AM. Reason: the numbers are still not correct

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    Have a look on getInetAddress() method of Socket class, which returns a reference to InetAddress class , and getHostAddress() method of InetAddress class which returns a textual representation of IP address of the remote machine to which the socket is connected.

  3. #3
    Wassa is offline Member
    Join Date
    Dec 2008
    Rep Power


    In my project a ServerThread is created to deal with any requests from a client.

    The client logs in with a username which is then set in a field on that thread.

    The server has a hashtable of all the connected sockets with the username as the key.

    It will know which client sent something as it would have come from that clients thread and it can reference the username

Similar Threads

  1. Multithread Chat server/client
    By gwaldarick in forum Advanced Java
    Replies: 3
    Last Post: 09-19-2009, 12:22 AM
  2. Multi Client/Server Chat Question
    By Kodak07 in forum Networking
    Replies: 3
    Last Post: 03-29-2009, 10:50 PM
  3. Replies: 2
    Last Post: 07-28-2008, 07:32 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:49 PM
  5. Replies: 3
    Last Post: 01-07-2008, 08:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts