示例#1
0
文件: UDP.java 项目: NZDIS/jgroups
 void doSend(byte[] data, InetAddress dest, int port) throws IOException {
   DatagramPacket packet;
   packet = new DatagramPacket(data, data.length, dest, port);
   if (sock != null) {
     sock.send(packet);
   }
 }
示例#2
0
文件: UDP.java 项目: NZDIS/jgroups
  /**
   * Workaround for the problem encountered in certains JDKs that a thread listening on a socket
   * cannot be interrupted. Therefore we just send a dummy datagram packet so that the thread 'wakes
   * up' and realizes it has to terminate. Should be removed when all JDKs support
   * Thread.interrupt() on reads. Uses sock t send dummy packet, so this socket has to be still
   * alive.
   *
   * @param dest The destination host. Will be local host if null
   * @param port The destination port
   */
  void sendDummyPacket(InetAddress dest, int port) {
    DatagramPacket packet;
    byte[] buf = {0};

    if (dest == null) {
      try {
        dest = InetAddress.getLocalHost();
      } catch (Exception e) {
      }
    }

    if (Trace.debug) {
      Trace.info("UDP.sendDummyPacket()", "sending packet to " + dest + ":" + port);
    }
    if (sock == null || dest == null) {
      Trace.warn(
          "UDP.sendDummyPacket()", "sock was null or dest was null, cannot send dummy packet");
      return;
    }
    packet = new DatagramPacket(buf, buf.length, dest, port);
    try {
      sock.send(packet);
    } catch (Throwable e) {
      Trace.error(
          "UDP.sendDummyPacket()",
          "exception sending dummy packet to " + dest + ":" + port + ": " + e);
    }
  }
示例#3
0
文件: UDP.java 项目: NZDIS/jgroups
 void handleDiagnosticProbe(InetAddress sender, int port) {
   try {
     byte[] diag_rsp = getDiagResponse().getBytes();
     DatagramPacket rsp = new DatagramPacket(diag_rsp, 0, diag_rsp.length, sender, port);
     if (Trace.trace) {
       Trace.info(
           "UDP.handleDiagnosticProbe()", "sending diag response to " + sender + ":" + port);
     }
     sock.send(rsp);
   } catch (Throwable t) {
     Trace.error(
         "UDP.handleDiagnosticProbe()",
         "failed sending diag rsp to " + sender + ":" + port + ", exception=" + t);
   }
 }