コード例 #1
0
  public void writeMessage(String msg) {
    Socket socket = null;
    TCPHandle handle = null;
    List<HangmanRules<Socket>.Player> players = hangmanRules.getPlayers();

    for (HangmanRules<Socket>.Player player : players) {
      socket = player.playerData;
      handle = new TCPHandle(socket);
      handle.write(msg);
    }
  }
コード例 #2
0
  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();
  }