Reputation: 1092
The client sends specific Objects multiple times over a socket to the server. Code looks like this:
public void send(Operation operation, Object o){
try{
out.writeObject(operation);
if (o != null) out.writeObject(o);
out.flush();
} catch (IOException e) {
System.err.println("Couldn't write to OutputStream");
}
}
In the Object is a HashMap from Integer to Integer, thats altering very often. The Server accepts the Message with:
User newUser = (User) oin.readObject();
The first time everything works well, the newUser Objects contains of the new received Object. But after the second, third, ... execution, the newUser Object always reads the old Object (the HashMap contains the old Values from the first communication). What am i doing wrong?
Thanks in advance!
Upvotes: 0
Views: 913
Reputation: 533520
You need to either call reset()
regularly to stop the cache of objects building up, preventing you from seeing changes to those objects, or you need to use writeUnshared()
I would consider calling reset()
before flush()
each time.
Upvotes: 3