check client still readable

This commit is contained in:
Ulisses Lima 2023-04-10 14:17:51 -03:00
parent 23c1abe3f2
commit 3ec56eab46
1 changed files with 3 additions and 2 deletions

View File

@ -45,8 +45,9 @@ public class EchoServer {
private static void answerWithEcho(ByteBuffer buffer, SelectionKey key) throws IOException {
SocketChannel client = (SocketChannel) key.channel();
client.read(buffer);
if (new String(buffer.array()).trim().equals(POISON_PILL)) {
int r = client.read(buffer);
if (r == -1 || new String(buffer.array()).trim()
.equals(POISON_PILL)) {
client.close();
System.out.println("Not accepting client messages anymore");
} else {