check client still readable
This commit is contained in:
parent
23c1abe3f2
commit
3ec56eab46
|
@ -45,8 +45,9 @@ public class EchoServer {
|
||||||
|
|
||||||
private static void answerWithEcho(ByteBuffer buffer, SelectionKey key) throws IOException {
|
private static void answerWithEcho(ByteBuffer buffer, SelectionKey key) throws IOException {
|
||||||
SocketChannel client = (SocketChannel) key.channel();
|
SocketChannel client = (SocketChannel) key.channel();
|
||||||
client.read(buffer);
|
int r = client.read(buffer);
|
||||||
if (new String(buffer.array()).trim().equals(POISON_PILL)) {
|
if (r == -1 || new String(buffer.array()).trim()
|
||||||
|
.equals(POISON_PILL)) {
|
||||||
client.close();
|
client.close();
|
||||||
System.out.println("Not accepting client messages anymore");
|
System.out.println("Not accepting client messages anymore");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue