Jump to content
  • Advertisement
Sign in to follow this  
tufflax

[java] Strange problem with Object streams

This topic is 4424 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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!