private void stopGame() {

    HashMap<EventHandler<?>, WorkerThread<?>> hMap = dispatcher.getMap();
    Iterator<?> it = hMap.keySet().iterator();

    WorkerThread<?> thread = null;
    Handle<?> handle = null;
    EventHandler<?> eh = null;

    while (it.hasNext()) {
      eh = (EventHandler<?>) it.next();
      handle = eh.getHandle();
      thread = hMap.get(eh);

      /* If it is the server-socket, then close it */
      if (handle instanceof AcceptHandle) {
        ((AcceptHandle) handle).close();
      }
      /* If it is the client-socket, then close it */
      else {
        ((TCPHandle) handle).close();
      }

      if (thread != null) {
        thread.cancelThread();
      }
    }
    hMap.clear();
  }
 public <T> void removeHandler(EventHandler<T> eh) {
   dispatcher.removeHandler(eh);
 }
 public <T> void addHandler(EventHandler<T> eh) {
   dispatcher.addHandler(eh);
 }