Ejemplo n.º 1
0
  private final void disconnectTheOtherGuy(PyroClient client) {
    PyroClient otherGuy = (PyroClient) client.attachment();

    // also disconnect the other guy
    if (otherGuy != null && !otherGuy.isDisconnected()) {
      client.attach(null);
      otherGuy.shutdown();
    }

    // note that you don't know whether you are the
    // other guy, or the other guy is! if either end
    // disconnects, the _other_ guy disconnects too.
  }
Ejemplo n.º 2
0
  @Override
  public void receivedData(PyroClient client, ByteBuffer data) {
    client.selector().checkThread();

    // send what you received to the other guy
    PyroClient otherGuy = (PyroClient) client.attachment();

    System.out.println(
        "traffic:" + client + " => " + otherGuy + " (" + data.remaining() + " bytes)");

    try {
      otherGuy.writeCopy(data);
    } catch (IllegalStateException exc) {
      // boo
    }
  }