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§;
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