Fix exception when receiving POISON_PILL

POISON_PILL is causing writing to closed client due to logic in code.
This commit is contained in:
luvarqpp
2020-07-01 15:39:19 +02:00
committed by GitHub
parent a6cbd51431
commit c36c2504ea

View File

@@ -49,12 +49,12 @@ public class EchoServer {
if (new String(buffer.array()).trim().equals(POISON_PILL)) {
client.close();
System.out.println("Not accepting client messages anymore");
}
} else {
buffer.flip();
client.write(buffer);
buffer.clear();
}
}
private static void register(Selector selector, ServerSocketChannel serverSocket) throws IOException {
SocketChannel client = serverSocket.accept();