/** * Listen for incoming and outgoing requests. If the {@code serverEnabled} * member is {@code false} the server for incoming requests is not * started. This starts the internal server thread that processes messages. * * @throws SocketException * when the transport is already listening for incoming/outgoing messages. * @throws IOException * if the listen port could not be bound to the server thread. */ public synchronized void listen() throws java.io.IOException { if (server != null) { throw new SocketException("Port already listening"); } serverThread = new ServerThread(); if (logger.isInfoEnabled()) { logger.info("TCP address " + getListenAddress() + " bound successfully"); } server = SNMP4JSettings.getThreadFactory().createWorkerThread( "DefaultTCPTransportMapping_" + getAddress(), serverThread, true); if (getConnectionTimeout() > 0) { // run as daemon socketCleaner = SNMP4JSettings.getTimerFactory().createTimer(); } server.run(); }