i am having a very weird situation in my code which i dont understand i am sending an object lets say O through a socket then i am changing the value of a variable in the object and sending it again but the second time when i print it on the client side, i am getting the same values as in the 1st object.
client code:
while(true){
try{
order=(Order)ois.readObject();
System.out.println(order);
}
server code:
public void sendOrder(Order o){
try {
out.writeObject(o);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
main method:
Server_Socket ss=new Server_Socket();
ss.sendOrder(o);
o.add(r2);
ss.sendOrder(o);
The value is definitely changing on the serverside before i send it, but i dont understand why on the client side its not showing that r2 added in the object.
The objects are being cached by the
ObjectOutputStream. To prevent this, callObjectOutputStream.reset()after each write. If you are sending simple objects that don’t contain other objects, usewriteUnshared()instead ofwriteObject().