InputStream.available () does not work

I am trying to use inputstream.available () to check if there is any data to read without blocking the stream. but it never returns any value> 0. Am I using it incorrectly?

while (slept < logOnTimeOut) {
    if ( sslSocket.getInputStream().available() > 0 )  {
        if (input.readLine().equals("OK") ) {    // todo: set timeout here
            System.out.println("Successfully Logged On");
            isLoggedOn = true;
            return true;
        }
    } else {
        Thread.sleep(500);
        slept += 500;
    }
}
+3
source share
1 answer

Read javadoc :

Returns an estimate of the number of bytes that can be read (or skipped) from this input stream without blocking by the next method call for this input stream. The next call may be the same thread or another thread. One reading or skipping this number of bytes will not block, but can read or skip fewer bytes.

, InputStream , . , .

, InputStream.available() , .

, read() , -1. available().

+5

Source: https://habr.com/ru/post/1789524/


All Articles