private void startInputThread(final ObjectInputStream input) {
    inputThread = new Thread(new Runnable() {
      @Override
      public void run() {
        ClientMessage message;

        while (connection != null && !connection.isClosed()) {
          try {
            message = (ClientMessage) input.readObject();
            handleMessageFromServer(message);
          }
          catch (SocketException | EOFException e) {
            break;
          }
          catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    });
    inputThread.start();
  }