How avoid blocking of SSLServerSocket when reaching end of input data?

The SSLServerSocket below blocks in in.read() in

while ( (b = in.read()) != -1 )

System.out.print((char)b);

when the last byte of the input data was read. The same happens if the input stream is wrapped into a buffered reader, i.e. the following loop doesn't terminate:

var br = new BufferedReader(new InputStreamReader(in));

String s;

while ( (s = br.readLine()) != null )

System.out.print(s);

According to Java Doc, InputStream.read should return -1 if the end of the stream has been reached.

Question: How can I avoid blocking when reaching the end of...

Read More »

By: StackOverFlow - 7 days ago

Related Posts