0

I've made a class which implements serializable. When I receive its object via my server-client application i'm only got its first instance, then no matter how many times the object has been modified the objectInputStream receives just the one what was sent for the first time.WHy?

This is actually a swing application There are running a chatpart and a gamepart on my application simultaneously.

the panel sends my game object to the server/client object

this.getServer1().sendGame(panel1.getMyGame());


 public void sendGame(Game g1) throws IOException{
       output.writeObject(g1);
       output.flush();
   }

the server or the client part is running on a thread

It reads data either from the gamepart or from the chatpart, the chatpart is works fine

Object next = input.readObject();
if (next instanceof Game) {
    game1 = (Game)next;
    panel1.setHisGame(game1);
}
else if (next instanceof String) {
    message = (String)next;
    ...
}

the gameclass is just a simple class with some String attributes and the implements Serializable

  • 1
    Can you show us the code and an example of how the result is wrong? – Pablo Oct 07 '12 at 22:27
  • 1
    The serialized data is "frozen": once the object has been written to the OOS (it has been serialized to a specific binary representation and shipped off) and future changes to the object will *not* magically alter the previous output. If multiple objects are written (in turn) to the OOS then each object will have to be read (in turn) from the OIS .. (I don't understand what the problem is then.) –  Oct 07 '12 at 22:27

1 Answers1

0

I've solved it. Before the panel sends mygameobject to the server, I had to create the whole new object and fill it with the data of mygameobject. That's the way it can work.