private synchronized DatagramSocket ensureSocket() throws SocketException { DatagramSocket s = socket; if (s == null) { s = new DatagramSocket(udpAddress.getPort()); s.setSoTimeout(socketTimeout); this.socket = s; } return s; }
protected synchronized DatagramSocket ensureSocket() throws SocketException { DatagramSocket s = socket; if (s == null) { s = new DatagramSocket(udpAddress.getPort()); s.setSoTimeout(socketTimeout); this.socket = s; } return s; }
private synchronized DatagramSocket ensureSocket() throws SocketException { DatagramSocket s = socket; if (s == null) { s = new DatagramSocket(udpAddress.getPort()); s.setSoTimeout(socketTimeout); this.socket = s; } return s; }
/** * Creates a UDP transport with an arbitrary local port on all local * interfaces. * * @throws IOException * if socket binding fails. */ public DefaultUdpTransportMapping() throws IOException { super(new UdpAddress(InetAddress.getLocalHost(), 0)); socket = new DatagramSocket(udpAddress.getPort()); }
/** * Creates a UDP transport with an arbitrary local port on all local * interfaces. * * @throws SocketException * if socket binding fails. */ public DefaultUdpTransportMapping() throws SocketException { super(new UdpAddress("0.0.0.0/0")); socket = new DatagramSocket(udpAddress.getPort()); }
/** * Creates a UDP transport with an arbitrary local port on all local * interfaces. * * @throws IOException * if socket binding fails. */ public DefaultUdpTransportMapping() throws IOException { super(new UdpAddress("0.0.0.0/0")); socket = new DatagramSocket(udpAddress.getPort()); }
public DtlsAddress(UdpAddress udpAddress) { super(udpAddress.getInetAddress(), udpAddress.getPort()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * If receiving new datagrams fails with a {@link SocketException}, this method is called to renew the * socket - if possible. * @param socketException * the exception that occurred. * @param failedSocket * the socket that caused the exception. By default, he socket will be closed * in order to be able to reopen it. Implementations may also try to reuse the socket, in dependence * of the {@code socketException}. * @return * the new socket or {@code null} if the listen thread should be terminated with the provided * exception. * @throws SocketException * a new socket exception if the socket could not be renewed. * @since 2.2.2 */ protected DatagramSocket renewSocketAfterException(SocketException socketException, DatagramSocket failedSocket) throws SocketException { if ((failedSocket != null) && (!failedSocket.isClosed())) { failedSocket.close(); } DatagramSocket s = new DatagramSocket(udpAddress.getPort(), udpAddress.getInetAddress()); s.setSoTimeout(socketTimeout); return s; }
@Override public void sendMessage(Address address, byte[] message) throws IOException { if (!(address instanceof UdpAddress)) { throw new IllegalArgumentException(); } try { node.sendSnmpMessage( ((UdpAddress)address).getInetAddress(), ((UdpAddress)address).getPort(), message ); } catch (SendPacketException e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } }
/** * 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} 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); }
/** * 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} addresses are reused which provides faster socket * binding if an application is restarted for instance. * * @throws SocketException * if socket binding fails. * @since 1.7.3 */ public DefaultUdpTransportMapping(UdpAddress udpAddress, boolean reuseAddress) throws SocketException { super(udpAddress); socket = new DatagramSocket(null); socket.setReuseAddress(reuseAddress); final SocketAddress addr = new InetSocketAddress(udpAddress.getInetAddress(), udpAddress.getPort()); socket.bind(addr); }
/** * 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(Address targetAddress, byte[] message) throws java.io.IOException { InetSocketAddress targetSocketAddress = new InetSocketAddress(((UdpAddress)targetAddress).getInetAddress(), ((UdpAddress)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)); }
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)); }
/** * 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} if the connection has been closed and * {@code false} if there was nothing to close. * @throws java.io.IOException if the remote address cannot be closed due to an IO exception. */ public synchronized boolean close(UdpAddress remoteAddress) throws IOException { if (logger.isDebugEnabled()) { logger.debug("Closing socket for peer address " + remoteAddress); } SocketEntry socketEntry = sockets.remove(new InetSocketAddress(remoteAddress.getInetAddress(), remoteAddress.getPort())); if (socketEntry != null) { socketEntry.closeSession(); return true; } return false; }
public void closeSession() { if (sslEngine.getSession().isValid()) { ByteBuffer outNetBuffer = ByteBuffer.allocate(getMaxInboundMessageSize()); try { SSLEngineResult sslEngineResult; do { sslEngineResult = sslEngine.wrap(ByteBuffer.allocate(0), outNetBuffer); outNetBuffer.flip(); socket.send(new DatagramPacket(outNetBuffer.array(), outNetBuffer.limit(), getPeerAddress().getInetAddress(), getPeerAddress().getPort())); } while ((sslEngineResult.getStatus() != Status.CLOSED) && (sslEngineResult.getHandshakeStatus() == NEED_WRAP)); } catch (Exception e) { logger.error("DTLSM: Exception while closing TLS session " + this + ": " + e.getMessage(), e); } } sslEngine.closeOutbound(); counterSupport.fireIncrementCounter(new CounterEvent(this, SnmpConstants.snmpTlstmSessionServerCloses)); TransportStateEvent e = new TransportStateEvent(DTLSTM.this, getPeerAddress(), TransportStateEvent.STATE_CLOSED, null); fireConnectionStateChanged(e); } }
public SocketEntry(UdpAddress address, boolean useClientMode, TransportStateReference tmStateReference) throws NoSuchAlgorithmException { super(address); this.tmStateReference = tmStateReference; if (tmStateReference == null) { counterSupport.fireIncrementCounter(new CounterEvent(this, SnmpConstants.snmpTlstmSessionAccepts)); } SSLEngineConfigurator sslEngineConfigurator = ensureSslEngineConfigurator(); SSLContext sslContext = sslEngineConfigurator.getSSLContext(useClientMode, tmStateReference); if (sslContext == null) { throw new RuntimeException("Failed to initialize SSLContext"); } this.sslEngine = sslContext.createSSLEngine(address.getInetAddress().getHostName(), address.getPort()); sslEngine.setUseClientMode(useClientMode); sslEngine.setNeedClientAuth(true); SSLParameters parameters = this.sslEngine.getSSLParameters(); parameters.setMaximumPacketSize(getMaxInboundMessageSize()); this.sslEngine.setSSLParameters(parameters); sslEngineConfigurator.configure(sslEngine); synchronized (DTLSTM.this) { sessionID = nextSessionID++; } }