title: Java Sockets - ArrayList loses information when I send over the connection
body: <p>I am having an issue sending some data over a socket, everything works great until I try to send an class that contains:  </p>
  
  <pre><code>int playerId  
  int command   
  int[] playerLocations
  </code></pre>
  
  <p>The data is received without any errors and command &amp; playerID are retained fine. However the <code>int[]</code> is the right size but the values are always reset to 0 for some reason, and I cant see why. I have tried using an ArrayList also but the same problem occurs.</p>
  
  <p>Server code for this part, the final for loop is the important part:</p>
  
  <pre><code>//now loop taking in turns
      while (true) {
  
          //first we get the player who's turn it is, and the corresponding thread for their client
          int playerTurn = game.getTurnNow();
          ClientThreadOnServer AciveClient = clientThreads.get(playerTurn);
          //then we send them a message saying it is their go
          try {
              AciveClient.out.writeObject(new TransferObject(playerTurn, 2, null));
              //we wait for them to click roll dice
              TransferObject reply = (TransferObject) AciveClient.in.readObject();
              //get the command back to roll the dice
              int command = reply.getCommand();
              int sender = reply.getPlayerId();
              // then make a move
              if (command == 2 &amp;&amp; sender == game.getTurnNow()) {
  
                  synchronized (this) { //synchronised to preven concurrent modification
                      System.out.println("command == 2");
                      game.rollDice();
                      game.takeGo();
                  }
              }
  
              //then send the updated game information to everyone
              for (int i = 0; i &lt; clientThreads.size(); i++) {
                  synchronized (this) {
  
                      int[] playerLoc = game.getPlayers();
                      System.out.println("server says:" + playerLoc[i]);
                      clientThreads.get(i).out.writeObject(new TransferObject(i, 1, playerLoc));
                  }
              }
  
  
          } catch (Exception ex) {
              Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
          }
  
      }
  
  }
  </code></pre>
  
  <p>where the system.out is "server says:" the correct value is printed, and when i debug the correct values can be seen in the variables section. </p>
  
  <p>Here is the object being sent:</p>
  
  <pre><code>import java.io.Serializable;
  
  public class TransferObject implements Serializable {
  
      private int playerId; //to be sent in forst data send to tell client which player they are
      private int turnNow; // ID of who's go it is now
      private int command; //0 = initialise, 1=game update, 2=roll, 3=end game
      private int[] playerLoc;
  
      public TransferObject(int playerId, int command, int[] playerLoc) {
          this.playerId = playerId;
          this.command = command;
          this.playerLoc = playerLoc;
      }
  
      public int getCommand() {
          return command;
      }
  
      public int getPlayerId() {
          return playerId;
      }
  
      public int getTurnNow() {
          return turnNow;
      }
  
      public int[] getPlayerLoc() {
          return playerLoc;
      }
  }
  </code></pre>
  
  <p>and the client receiving section, command 1 is the bit that should print out the correct data but just prints "...on square 0"</p>
  
  <pre><code> while (true) {
          try {
              int command = -1; //reset command to something not used in order to prevent confusion
              TransferObject transObj = (TransferObject) in.readObject();
              command = transObj.getCommand();
              if (command == 0) {//initialisation
                  playerId = transObj.getPlayerId();
  
              } else if (command == 1) {//gui update
                  for (int i = 0; i &lt; transObj.getPlayerLoc().length; i++) {
                      //need to have gui stuff here eventually
                      System.out.println("Player " + i + " on square " + transObj.getPlayerLoc()[i]);
                  }
  
              } else if (command == 2) {//ask for a roll
                  JOptionPane.showMessageDialog(null, "Roll the dice?", "It's your go!", JOptionPane.QUESTION_MESSAGE);
                  TransferObject objOut = new TransferObject(playerId, 2, null); //Send request for roll - NULL COULD BE AN ISSUE
                  out.writeObject(objOut);
  
              } else if (command == 3) {//end game
                  JOptionPane.showMessageDialog(null, "Game Over", "Player " + transObj.getPlayerId() + " wins!", JOptionPane.INFORMATION_MESSAGE);
                  break; //exit loop and game ends
              } else {
                  System.out.println("Data Transfer Error");
              }
  
          } catch (Exception ex) {
              Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  }
  </code></pre>
  
  <p>Sorry there is so much code here, hopefully somebody can make sense of it. If you need any more info let me know.</p>