4 Replies Latest reply on Jun 2, 2010 5:45 PM by jtahlborn

    deserialization / readObject problem

      Hi people

      I am in the making of a simple 2D multiplayer game.
      The server and clients are communicating through ObjectOutput/ Input streams (through Sockets).

      The server contains all the game logic, and it sends a serialized GameData class to the clients
      so they can draw the graphics accordingly to the events in the game.

      The problem is, the client only reads data from its objectinputstream successfully once, then it just doesnt work.
      It seems that after the first call of objectRead() it always just gets the same object with every call of objectRead.

      It is SURE that it the objectRead gets it successfully at least ONCE, because the client draws the graphics of the game after joining, but it doesn't move,
      it's like the client captures the state of the game in the moment of joining.

      There are no exceptions thrown, there are no problems on the serverside(it always writes out different GameData instances by writeObject(GameData)).

      I write the contents of the gd class every time on console after the call of GameData gd=(GameData) In. readObject();
      and it's always the same and hence, the drawn graphics are the same.
      I also write the contents of the sent GameData class every time on console after the call of out.writeObject( GameData instance); on the server side
      and it's always updated accordingly to the logic of the game.

      Please help, the deadline is close!
      while (true) {
                          // Get the game data from the server
                          try {
                                         .println("client: dataupdater class : trying to read data from server");                    
                                              GameData gd = (GameData) In.readObject();               
      //at this point i write out the contents of gd to the console, and it's always the same!!
      //I spare you of that code.
                               System.out.println("Data read .");
                          catch (SocketException s) {
                               System.out.println("Disconnected from server.");
                          catch (IOException ie) {
                          catch (Exception e) {
                          try {
                          } catch (InterruptedException e) 
      Also the serverside code, because it cant hurt.
           GameData gd = logic.exportGameData();
                      System.out.println("Number of entities: " + gd.entities.length);
                for (int i = 0; i < gd.entities.length; i++) {
                     Entity entity = gd.entities;
                     System.out.println(entity.getClass() + " PosX: " + entity.getX()
                               + " PosY: " + entity.getY());

                // synchronized (outputStreams) {
                // For each client ...
                for (Enumeration<ObjectOutputStream> e = getOutputStreams(); e
                          .hasMoreElements();) {
                     // ... get the output stream ...
                     ObjectOutputStream out = (ObjectOutputStream) e.nextElement();
                     // ... and send the message
                     try {
                     } catch (IOException ie) {
      Edited by: mostKeltem on Jun 2, 2010 9:47 AM