End the outer loop when the call readLine()returns null.
No exception occurs when the server normally closes the connection. The stream should return nullto signal completion of data.
This can be done using a loop:
public void run() {
try {
while (true) {
String line = input.readLine();
if (line == null)
break;
...
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
source
share