Sign in to follow this  

[java] Strange problem with Object streams

This topic is 4207 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey! I'm writing a little multiplayer game and it goes kind of well. But right now I'm having a problem. The problem is that when I'm using ObjectInputStream/OutputStream the Objects are not transfered correctly... I want to send a "ToServerPacket" to the server from the client. The ToServerPacket has only one instance variable (right now); a Position. The Position is a very simple class. It has only short x; and short y; and get/set methods. The ToServerPacket has a toString() which returns a String with the x and y values shown. Both ToServerPacket and Position implement Serializable. What happends is that when I send a ToServerPacket, I receive a ToServerPacket on the other side, so far so good, but the values (x and y in the Position) are not correct! Whatever Position I send, I get x==0 and y==0 when I read them on the other side. The way I tryed it was like this: ToServerPacket p = new ToServerPacket(...); System.out.println(p.toString()); out.writeObject(p); and Object o = in.readObject(); System.out.println(o.toString()); The toString() works but as I said the values after I read are always 0 and 0. Bummer... :( Edit: It appears that the values are not always 0 and 0, but instead equal to the values in the very first packet that was sent. Some code: http://rafb.net/paste/results/0ppUfA98.html Fixed: If I create a new Position and send that instead of referncing to the same old Position, it works. But why? :P [Edited by - tufflax on June 25, 2006 1:43:50 PM]

Share this post


Link to post
Share on other sites

This topic is 4207 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this