msg.writeInt(tunnel.getSourcePort());
msg.writeString(destHost);
msg.writeInt(tunnel.getDestination().getPort());
Request request = new Request(TunnelingService.START_REMOTE_TUNNEL, msg.toByteArray());
agent.sendRequest(request, false);
} catch(IOException ex) {
ex.printStackTrace();
}
running = true;
if (log.isInfoEnabled())
log.info("Starting remote listener on " + tunnel.getSourcePort());
try {
while (running) {
try {
Socket s = listeningSocket.accept();
if (log.isInfoEnabled())
log.info("Received new connection on " + tunnel.getSourcePort() + " from " + s.getInetAddress());
RemoteForwardingChannel channel = new RemoteForwardingChannel(this, s, tunnel, launchSession);
try {
agent.openChannel(channel);
} catch (ChannelOpenException e) {
log.error("Error opening channel. Remote tunnel remaining open but closing connection.", e);
try {
s.close();
} catch (IOException ioe) {
}
}
} catch (IOException e) {
if (running) {
log.error("IO error waiting for connection, stopping remote tunnel.", e);
}
}
}
} finally {
Request request = new Request(TunnelingService.STOP_REMOTE_TUNNEL, msg.toByteArray());
try {
agent.sendRequest(request, false);
} catch (IOException e) {
}