Why does the SshSession InputStream's available method always return zero?

This is most likely because you are using the API in single threaded mode.

When your using the API in single threaded mode there is no way for the API to know there is data waiting on the socket before a read attempt is performed. This is because there is no background thread to read data separately from the socket and queue/buffer it for you. The only way we can determine if data is available is when you actually call the InputStream's read method.

If you want available to work you have to have a background thread. You do this by passing a true value for the SshConnector's connect method's buffered parameter (3rd parameter).

SshClient sshClient = sshConnector.connect(
new SocketTransport("localhost", 22), "lee", true);

Alternatively, buffer the data yourself or refactor your code to avoid using available method. 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.