/** Closes all open sockets and stops the internal server thread that processes messages. */
 public void close() {
   ServerThread st = server;
   if (st != null) {
     st.close();
     try {
       st.join();
     } catch (InterruptedException ex) {
       logger.warn(ex);
     }
     server = null;
     for (Iterator it = sockets.values().iterator(); it.hasNext(); ) {
       SocketEntry entry = (SocketEntry) it.next();
       try {
         synchronized (entry) {
           entry.getSocket().close();
         }
         logger.debug("Socket to " + entry.getPeerAddress() + " closed");
       } catch (IOException iox) {
         // ingore
         logger.debug(iox);
       }
     }
     if (socketCleaner != null) {
       socketCleaner.cancel();
     }
     socketCleaner = null;
   }
 }
 /**
  * Closes a connection to the supplied remote address, if it is open. This method is particularly
  * useful when not using a timeout for remote connections.
  *
  * @param remoteAddress the address of the peer socket.
  * @return <code>true</code> if the connection has been closed and <code>false</code> if there was
  *     nothing to close.
  * @since 1.7.1
  */
 public synchronized boolean close(Address remoteAddress) throws IOException {
   if (logger.isDebugEnabled()) {
     logger.debug("Closing socket for peer address " + remoteAddress);
   }
   SocketEntry entry = (SocketEntry) sockets.remove(remoteAddress);
   if (entry != null) {
     synchronized (entry) {
       entry.getSocket().close();
     }
     logger.info("Socket to " + entry.getPeerAddress() + " closed");
     return true;
   }
   return false;
 }
 /**
  * Closes the socket and stops the listener thread.
  *
  * @throws IOException
  */
 public void close() throws IOException {
   boolean interrupted = false;
   WorkerTask l = listener;
   if (l != null) {
     l.terminate();
     l.interrupt();
     if (socketTimeout > 0) {
       try {
         l.join();
       } catch (InterruptedException ex) {
         interrupted = true;
         logger.warn(ex);
       }
     }
     listener = null;
   }
   DatagramSocket closingSocket = socket;
   if ((closingSocket != null) && (!closingSocket.isClosed())) {
     closingSocket.close();
   }
   socket = null;
   if (interrupted) {
     Thread.currentThread().interrupt();
   }
 }
 public void sendMessage(
     UdpAddress targetAddress, byte[] message, TransportStateReference tmStateReference)
     throws java.io.IOException {
   InetSocketAddress targetSocketAddress =
       new InetSocketAddress(targetAddress.getInetAddress(), targetAddress.getPort());
   if (logger.isDebugEnabled()) {
     logger.debug(
         "Sending message to "
             + targetAddress
             + " with length "
             + message.length
             + ": "
             + new OctetString(message).toHexString());
   }
   DatagramSocket s = ensureSocket();
   s.send(new DatagramPacket(message, message.length, targetSocketAddress));
 }