diff --git a/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java index 8cf2e941fe..9e9edcd0ba 100644 --- a/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java +++ b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java @@ -49,11 +49,11 @@ 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(); } - - buffer.flip(); - client.write(buffer); - buffer.clear(); } private static void register(Selector selector, ServerSocketChannel serverSocket) throws IOException {