views:

104

answers:

1

hello i have a basic client-server system running using java sockets.

my problem is, that an object that i send from the client to the server does not contain the correct data after it has been sent once.

the first time i send it, it arrives with the correct values, but when i send it another time with different values, it still arrives at the server with the same values as the first time. it also happens if i send a completely different instance of that class. it always arrives with the data, which have been sent the very first time.

when i try this with other objects like java.lang.String it seems to work.

the problematic class looks like this:

public class Vector3f implements Serializable {

    private static final long serialVersionUID = 2838034155614698213L;

    public float x, y, z;
}

i use objectinputstream and objectoutputstream on both the server and the client to send and receive objects.

let me know, if you need any more information about the system.

thanks!

+2  A: 

My guess is that you're changing the values of the fields and then retransmitting the same object. The ObjectOutputStream will notice that it's already sent the original object, and just send a reference the second time.

You could avoid this by calling reset() on the ObjectOutputStream - but I'd be tempted to just use separate instances anyway, possibly even making the class immutable. (Public mutable fields are almost never a good idea.)

Jon Skeet
yepp, that was it, thanks!
clamp