/** * Creates a UDP transport with optional reusing the address if is currently in timeout state * (TIME_WAIT) after the connection is closed. * * @param udpAddress the local address for sending and receiving of UDP messages. * @param reuseAddress if <code>true</code> addresses are reused which provides faster socket * binding if an application is restarted for instance. * @throws IOException if socket binding fails. * @since 1.7.3 */ public DefaultUdpTransportMapping(UdpAddress udpAddress, boolean reuseAddress) throws IOException { super(udpAddress); socket = new DatagramSocket(null); socket.setReuseAddress(reuseAddress); final SocketAddress addr = new InetSocketAddress(udpAddress.getInetAddress(), udpAddress.getPort()); socket.bind(addr); }
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)); }
/** * Creates a UDP transport on the specified address. The address will not be reused if it is * currently in timeout state (TIME_WAIT). * * @param udpAddress the local address for sending and receiving of UDP messages. * @throws IOException if socket binding fails. */ public DefaultUdpTransportMapping(UdpAddress udpAddress) throws IOException { super(udpAddress); socket = new DatagramSocket(udpAddress.getPort(), udpAddress.getInetAddress()); }