I am trying to use inputstream.available () to check if there is any data to read without blocking the thread. but it never return any value > 0. am I using it wrong?
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;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…