/**
   * Constantly reads the client's input stream. Sends all objects that are read to the server. Not
   * to be called.
   */
  public final void run() {
    server.clientConnected(this);

    // This loop reads the input stream and responds to messages
    // from clients
    try {
      // The message from the client
      Object msg;

      while (!readyToStop) {
        // This block waits until it reads a message from the client
        // and then sends it for handling by the server
        msg = input.readObject();
        server.receiveMessageFromClient(msg, this);
      }
    } catch (Exception exception) {
      if (!readyToStop) {
        try {
          closeAll();
        } catch (Exception ex) {
        }

        server.clientException(this, exception);
      }
    }
  }
  /**
   * Closes the client. If the connection is already closed, this call has no effect.
   *
   * @exception IOException if an error occurs when closing the socket.
   */
  public final void close() throws IOException {
    readyToStop = true; // Set the flag that tells the thread to stop

    try {
      closeAll();
    } finally {
      server.clientDisconnected(this);
    }
  }