I\'m using JSch 0.1.50 to set up a connection to the remote server for my CI Jenkins plugin. Let\'s assume I\'m trying to use here session.connect(60000);
for t
If you check how the Util.createSocket
is implemented, you will see that the timeout
defines an upper limit of the connection only, not a lower limit, because the timeout
is strangely not passed to an underlying Socket
.
Those 20 seconds is probably an OS-level default limit.
To override it, try implementing the SocketFactory and attach it to the session using the Session.setSocketFactory.
In the factory use the Socket.connect(SocketAddress endpoint, int timeout).
Something like:
public class SocketFactoryWithTimeout implements SocketFactory {
public Socket createSocket(String host, int port) throws IOException,
UnknownHostException
{
socket=new Socket();
int timeout = 60000;
socket.connect(new InetSocketAddress(host, port), timeout);
return socket;
}
public InputStream getInputStream(Socket socket) throws IOException
{
return socket.getInputStream();
}
public OutputStream getOutputStream(Socket socket) throws IOException
{
return socket.getOutputStream();
}
}