I’m developing a simple multiplayer game with a server. The concept is to send the object “game” after every turn of a player to all clients. It contains all information the clients need. It works well the first time. After the second time the values of the object in the client aren’t changed. It is confirmed that the values are changed on the server and I also set the object to null on the client side before reading. I am not experienced in Java. Is it possible that “Java” thinks because it is the same instance it will not read the new values and just reactivate the old values (maybe from a cache)?
Client Code
this.game = null;
this.game = (Game) ois.readObject();
Server Code
aCPS.get(i).oos.writeObject(game);
Game
public class Game implements Serializable {...}
Please tell me if you need more code. Thanks.
If you write the same object to an
ObjectOutputStreamwithout resetting, you will get the same object. This is how Java Serialisation handles arbitrary object graphs.To fix, best off using a fresh
ObjectOutputStream. You can callreseton it. Or use immutable objects or use something else for serialisation.