Exemplo n.º 1
0
  /** Thread that will handle messages coming across the socket */
  private void listenThread() {

    /* Note that the thread is starting */
    Bugout.msg("Link " + address + ": THREAD START");

    /* Now read in data from the socket and pass it to the host */
    try {
      Message message;
      while (running && (message = socket.receive()) != null) {
        Bugout.msg("Link " + address + ": received: " + new MessagePointer(message));
        host.receiveAnnouncement(message);
      }
    } catch (NetworkException e) {
      Bugout.err("Link " + address + ": " + e.getMessage());
    } catch (IncorrectFormatException e) {
      Bugout.err(
          "Link "
              + address
              + ": received a message that is incorrectly formatted:"
              + e.getMessage());
    }

    /* If we exit the while loop, remove and close this link */
    host.removeLink(this);
    Bugout.msg("Link " + address + ": THREAD END");
    stop();
  }
Exemplo n.º 2
0
  /** Stop the thread. */
  public void stop() {
    /* Note that we're stopping on the console */
    Bugout.err("Link " + address + ": STOPPING");

    /* Close the socket */
    running = false;
    try {
      socket.close();
    } catch (IOException e) {
      Bugout.err("Link " + address + ": while stopping: " + e.getMessage());
    }
  }