How do I configure a connect timeout?

The timeout should be set on the transport object you pass into the SshConnector.connect calls. The API actually takes a connected socket, it does not perform any of the connection itself inside the API.

As the SocketTransport class that is used in our examples only has limited constructors you cannot use that to achieve a connect timeout.

You have to create and connect your Socket externally before passing it into the API if you want to use a connect timeout.

SocketAddress sockaddr = new InetSocketAddress(host, port); 
Socket sock = new Socket(); 
sock.connect(sockaddr, 5000);

Then wrap this in SocketWrapper and pass this into the API

SshConnector con = SshConnector.getInstance();
SshClient ssh = con.connect(new SocketWrapper(sock), 
"user", 
true);
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.