/** * Start listening for incoming connections and forward to remote host as a channel and ensure that the thread is registered. * This is useful if for instance {@link #close() is called from another thread} * * @throws IOException */ public void listen(Thread runningThread) throws IOException { this.runningThread = runningThread; log.info("Listening on {}", serverSocket.getLocalSocketAddress()); while (!runningThread.isInterrupted()) { try { final Socket socket = serverSocket.accept(); log.debug("Got connection from {}", socket.getRemoteSocketAddress()); startChannel(socket); } catch (SocketException e) { if (!serverSocket.isClosed()) { throw e; } } } if (serverSocket.isClosed()) { log.debug("LocalPortForwarder closed"); } else { log.debug("LocalPortForwarder interrupted!"); } }
/** * Start listening for incoming connections and forward to remote host as a channel and ensure that the thread is registered. * This is useful if for instance {@link #close() is called from another thread} * * @throws IOException */ public void listen(Thread runningThread) throws IOException { this.runningThread = runningThread; log.info("Listening on {}", serverSocket.getLocalSocketAddress()); while (!runningThread.isInterrupted()) { try { final Socket socket = serverSocket.accept(); log.debug("Got connection from {}", socket.getRemoteSocketAddress()); startChannel(socket); } catch (SocketException e) { if (!serverSocket.isClosed()) { throw e; } } } if (serverSocket.isClosed()) { log.debug("LocalPortForwarder closed"); } else { log.debug("LocalPortForwarder interrupted!"); } }