@Override
    public void run() {
      serverThread.setStop(true);
      clientThread.setStop(true);

      for (String connection : connections.keySet()) {
        ConnectionHandler handler = connections.get(connection);
        handler.setStop(true);
        try {
          // wait for the thread to finish
          handler.join();
        } catch (InterruptedException e) {

        }
      }

      connections.clear();
    }