Help with client/server communications

R

RCarter

Hi.
I have a client/server application where the server accepts connection
from clients, and it starts a thread for each client.
Client and the thread class communicate by a class Data that have an
int to identify the type of the message (result, error, login ok,
etc.) and there is a function execute(int) with a switch that do the
right things. Data also have a DefaultListModel diffused by the server
every time a client connects or disconnects and used by the client to
update its list of users connected.
Now the problem is:
- I activate the Server, there are no client connected... OK;
- I start a client, I logged in, on the server's list appears the
name of the user connected, the server sends the list to all threads
started (only one for the moment) and threads sends the list to its
client, the list arrived and appers on the client list with only one
entry (itself)... OK;
- I start another client, now on the server's list there are 2 names,
the server sends the new list to all its threads (I've controlled with
a lot of System.out and it sends the correct DefaultListModel to both
threads), both threads now have the correct list (I've controlled) and
sends it to their client; the client just logged receives the correct
list (with 2 users) and it displays it correctly but... the old client
receives another time the old list (with only itself, I've controlled
also this) and so it don't refresh the JList....WHY???

I've tried to send directly the JList and not the DefaultListModel,
but the result is the same.
If anyone can help me... Thank you in advance!

RCarter
 
G

Gordon Beaton

- I start another client, now on the server's list there are 2
names, the server sends the new list to all its threads (I've
controlled with a lot of System.out and it sends the correct
DefaultListModel to both threads), both threads now have the correct
list (I've controlled) and sends it to their client; the client just
logged receives the correct list (with 2 users) and it displays it
correctly but... the old client receives another time the old list
(with only itself, I've controlled also this) and so it don't
refresh the JList....WHY???

It sounds like you're sending the data with an ObjectOutputStream. The
OOS caches object references and won't send the contents of the same
object more than once. The second and subsequent times you send it,
the OOS sends only a reference to the remote ObjectInputStream where
the (old) object is reconstructed. That's why changes aren't visible.

You have two alternatives: send a completely *new* object each time,
or reset the ObjectOutputStream before sending the object additional
times.

If the amount of data starts to get large, you might want to think
about only sending information about changes, and let the client
manage his own JList.

Read more here:
http://java.sun.com/products/jdk/serialization/faq/#handle

/gordon
 
A

Ajit

Hi,

Send the list of connected users to the user who is going to connect
and send only updated user details to the other connected users.

Regds,

Ajit
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top