private void startOutputThread(final ObjectOutputStream output) {
    outputThread = new Thread(new Runnable() {
      @Override
      public void run() {
        ServerMessage message;
        while (connection != null && !connection.isClosed()) {
          try {
            message = messageQueue.take();
            output.writeObject(message);
            output.flush();
          }
          catch (SocketException | EOFException e) {
            break;
          }
          catch (InterruptedException | IOException e) {
            // continue
          }
        }
      }
    });
    outputThread.start();
  }