title: Xstream not created in thread
body: <p>I'm debugging the unability to send serialized by XStream object via socket (it is created in dedicated thread, by the manual). And i've added debugging messages to send from client to server.</p>
  
  <p>Client side</p>
  
  <pre><code>public class SocketClient implements Runnable {
  
  static Socket client;
  static Thread t;
  static PrintWriter out;
  static BufferedReader in;
  static String strIn;
  
  public static boolean CreateClientSocket(InetAddress ip) {
      try {
          client = new Socket();
          client.connect(new InetSocketAddress(ip, 9999), 0);
          t = new Thread(new SocketClient());
          t.start();
          return true;
      } catch (UnknownHostException ex) {
          Logger.getLogger(SocketServer.class.getName()).log(Level.SEVERE, null, ex);
          return false;
      } catch (IOException ex) {
          Logger.getLogger(SocketServer.class.getName()).log(Level.SEVERE, null, ex);
          return false;
      }
  }
  
  public static void closeClient() {
      try {
          client.close();
      } catch (IOException ex) {
          Logger.getLogger(SocketServer.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  
  public static void sendClientPlayertoServer() {
      try {
          out.println("procedure start");
          XStream xs =new XStream();
          out.println("xs created");
          GameSave gs = new GameSave();
          out.println("gs created");
          ArrayList&lt;PlayerSerialize&gt; listps = new ArrayList&lt;PlayerSerialize&gt;();
          PlayerSerialize ps = new PlayerSerialize();
          out.println("ps created");
          ps.getPlayerData(Players.players.get(1));
          listps.add(ps);
          gs.playersSerialize = listps;
          gs.gamedate = Dateutils.gamedate;
          String s =xs.toXML(gs);
          out.println("gs converted");
          String[] ssplit = s.split("\n");
          out.println("clientplayertoserver");
          for (String spart : ssplit) {
              out.println(spart);
          }
          out.println("clientready");
          out.flush();
      } catch (Exception e) {
          e.printStackTrace();
          JOptionPane.showMessageDialog(null, e.toString());
          Utils.debugWriteStringToFile(e.toString(), "sendclientexception");
      }
  }
  
  public static void sendClientReady() {
      out.println("clientready");
      out.flush();
  }
  
  public static void sendClientIsAlive() {
      out.println("clientisalive");
      out.flush();
  }
  
  @Override
  public void run() {
      try {
          out = new PrintWriter(client.getOutputStream(), true);
          in = new BufferedReader(new InputStreamReader(client.getInputStream()));
          while ((strIn = in.readLine()) != null) {
              System.out.println(strIn);
              if (strIn.contains("side")) {
                  strIn = in.readLine();
                  System.out.println(strIn);
                  DialogMultiplayerStart.setSide(strIn);
              } else if (strIn.contains("startgame")) {
                  DialogMainField.startNewGame(true, false, DialogMultiplayerStart.isFirstPlayerUSSR);
                  DialogMultiplayerStart.callDispose();
              } else if (strIn.contains("serverprestige")) {
                  strIn = in.readLine();
                  System.out.println(strIn);
                  Players.players.get(0).prestige = Integer.parseInt(strIn);
              } else if (strIn.contains("clientplayertoclient")) {
                  strIn = in.readLine();
                  System.out.println(strIn);
                  XStream xs = new XStream();
                  GameSave gs = (GameSave) xs.fromXML(strIn);
                  Players.players.get(1).getPlayerSerializeData(gs.playersSerialize.get(0));
              } else if (strIn.contains("refreshgamefield")) {
                  PanelNextTurn.refreshGameField();
              }
          }
      } catch (IOException ex) {
          Logger.getLogger(SocketClient.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Server side: </p>
  
  <pre><code>public class SocketServer implements Runnable {
  
  static ServerSocket server;
  static Socket client;
  static Thread t;
  static PrintWriter out;
  static BufferedReader in;
  static String strIn;
  
  public static void CreateServerSocket() {
      try {
          server = new ServerSocket(9999);
          t = new Thread(new SocketServer());
          t.start();
      } catch (IOException ex) {
          Logger.getLogger(SocketServer.class.getName()).log(Level.SEVERE, null, ex);
      }
  
  }
  
  public static void closeServer() {
      try {
          server.close();
      } catch (IOException ex) {
          Logger.getLogger(SocketServer.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  
  public static void sendSide(String side) {
      out.println("side");
      out.println(side);
  }
  
  public static void sendStartGame() {
      out.println("startgame");
  }
  
  public static void sendServerIsAlive() {
      out.println("serverisalive");
  }
  
  public static void sendServerPrestige() {
      out.println("serverprestige");
      out.println(Players.players.get(0).prestige);
  }
  
  public static void sendRefreshField() {
      out.println("refreshgamefield");
  }
  
  public static void sendClientPlayertoClient() {
      XStream xs = new XStream();
      GameSave gs = new GameSave();
      ArrayList&lt;PlayerSerialize&gt; listps = new ArrayList&lt;PlayerSerialize&gt;();
  
      PlayerSerialize ps = new PlayerSerialize();
      ps.getPlayerData(Players.players.get(1));
      listps.add(ps);
      gs.playersSerialize = listps;
      gs.gamedate = Dateutils.gamedate;
      String s = xs.toXML(gs);
      Utils.debugWriteStringToFile(s, "clientplayertoclient");
      out.println("clientplayertoclient");
      out.println(s);
  }
  
  @Override
  public void run() {
  
      try {
          client = server.accept();
          DialogMultiplayerStart.updateAfterConnection();
          out = new PrintWriter(client.getOutputStream(), true);
          in = new BufferedReader(new InputStreamReader(client.getInputStream()));
          out.println("test from server");
  
          while ((strIn = in.readLine()) != null) {
              System.out.println(strIn);
              if (strIn.contains("clientplayertoserver")) {
                  String s=new String();
                  while(!(strIn=in.readLine()).contains("clientready")){
                      s=s+strIn;
                  }
                  XStream xs = new XStream();
                  GameSave gs = (GameSave) xs.fromXML(s);
                  Players.players.get(1).getPlayerSerializeData(gs.playersSerialize.get(0));
               PanelNextTurn.setClientReady();
              } else if (strIn.contains("clientisalive")) {
                  DialogMainField.startNewGame(true, true, DialogMultiplayerStart.isFirstPlayerUSSR);
                  DialogMultiplayerStart.callDispose();
  
              }
          }
          out.println("CYCLE ENDED!!!");
      } catch (IOException ex) {
          out.println("caught error");
          Logger.getLogger(SocketServer.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  </code></pre>
  
  <p>Setting side (sendSide) and start game (sendStartGame) commands works great, checking that server and clients are alive after game data load - also works fine. But no way of sending client turn to server.</p>
  
  <p>The problem is that server side receives only "procedure start" message and there is no file with logged error. Are there any limitations or problems of using XStream this way? What should I use as a different way to send object via socket?</p>