Search code examples
javasocketsobjectinputstreamobjectinputstream

Java:ObjectInputStream returns same Object


I am programming java network using sockets and exchanging data between the remote programs using a Simple objects.

In present case I have an ObjectInputStream constructed using :

new ObjectInputStream(Socket.getInputStream())

So I am using writeObject method to write a Object that contains some String fields.

However the receiver when calls readObject it always returns the same object.

To check this I set one of the string fields to store current time. While writing the object its always different time for each object. but received object all show same single time in the string field.

Clearly speaking every object returned after each call to ObjectInputStream.ReadObject is a exact clone of other

why is this happening?


Solution

  • try doing objectInputStream.reset();