Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-23-2008, 03:53 AM
Member
 
Join Date: Dec 2008
Posts: 1
Rep Power: 0
kathleenr is on a distinguished road
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)

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 03:54 AM. Reason: the numbers are still not correct
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-24-2008, 07:58 AM
Senior Member
 
Join Date: Dec 2008
Posts: 107
Rep Power: 0
dswastik is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-27-2008, 08:02 PM
Member
 
Join Date: Dec 2008
Posts: 5
Rep Power: 0
Wassa is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Client/Server Chat Question Kodak07 Networking 3 03-29-2009 10:50 PM
Multithread Chat server/client gwaldarick Advanced Java 2 12-19-2008 07:17 AM
[SOLVED] simple server chat program, using InputStream and OutputStream. NullPointerE jim478 New To Java 2 07-28-2008 07:32 PM
When to use –client and -server option while running a java program Java Tip java.lang 0 04-04-2008 02:49 PM
[B]Simple Client connected to server but not exchanging messages[/B] JavaEmpires Networking 3 01-07-2008 07:01 AM


All times are GMT +2. The time now is 03:13 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org