private void prepareClient() throws IOException {
    logger.info("Waiting for client's name");
    Message mes = Operations.receive(in);
    setClientName((String) mes.getValue());
    logger.info("Username for " + s.getInetAddress() + " received: " + userName);

    users.add(this);
    logger.info("User " + getClientName() + " has been added to the userlist.");

    messages = new Messages();
    logger.info("Message list created");

    if (!history.containsKey(userName)) {
      history.put(userName, messages);
    } else {
      messages = history.get(userName);
    }
    messages.addObserver(this);
    logger.info("Message list assigned to history");

    logger.info("Sending the list of users.");
    Operations.sendUserNamesList(users.getUserNames(), out);
    logger.info("Userlist has been sent");
  }
 public InetSocketAddress getRemoteAddress() {
   Socket s = connection.getChannel().socket();
   InetAddress ia = s.getInetAddress();
   int port = s.getPort();
   return new InetSocketAddress(ia, port);
 }
 public String toString() {
   return getClientName() + " [" + s.getInetAddress() + "]";
 }