Viewing Clients in a Chat Program

J

joanduan

I have developed a chat program in java. using server socket and
simple socket. The server and client open a DataInputStream and
DataOutputStream Reader. There are two problems that i want to
resolve.

1) I want to show all the currently connected clients in a JList
present in Client GUi.

2) I also want to be able to communicate privately with the other
users and also send binary files like images and audio files

I have created a TrackUser Class which stores info about the user.
However the main problem remains the same, How to send the information
back to the client and display it in a Jlist cause there's gonna be a
lot of info flowing between the server and the client (redirected
obviously from another client) the main problem lies in identifying
which part belongs to userinfo and which part belongs to the chat
portion. When the server sends user information to the client that
appears in the Client textarea whereas i want the list of users in a
JList and the chat in the textarea.

Thanx
 
R

Roman Vottner

hi,
1) I want to show all the currently connected clients in a JList
present in Client GUi.

...

I have created a TrackUser Class which stores info about the user.
However the main problem remains the same, How to send the information
back to the client and display it in a Jlist cause there's gonna be a
lot of info flowing between the server and the client (redirected
obviously from another client) the main problem lies in identifying
which part belongs to userinfo and which part belongs to the chat
portion. When the server sends user information to the client that
appears in the Client textarea whereas i want the list of users in a
JList and the chat in the textarea.

i would create a hashtable on the server which contains the username as key
(or an id if multiple names should be supported) and the TrackUser-class
which contains the users' information as the value. on login of a user you
iterate through the hashtable of online-users and send just the name of the
user who loged in to them.

the sending message contains for example an additional header (just a fixed
size of data) which defines the type of message (userinfo, chatmsg, ...)
the message represents and the message itself. thisway you can catch the
whole message at receiving and deceide what to do with it as you read the
header of the message.

at http://www.brackeen.com/javagamebook/ you can download the source of
chapter6 which creates a client/server game- and chat-architecture, which
can be extended by "modules" or "plugins". it uses java.nio to communicate
but the idea itself should work for Serversockets too.

lg,
roman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top