diff --git a/src/main/java/org/jboss/netty/example/securechat/SecureChatClient.java b/src/main/java/org/jboss/netty/example/securechat/SecureChatClient.java index bd285c2d29..8bcd949394 100644 --- a/src/main/java/org/jboss/netty/example/securechat/SecureChatClient.java +++ b/src/main/java/org/jboss/netty/example/securechat/SecureChatClient.java @@ -90,7 +90,16 @@ public class SecureChatClient { if (line == null) { break; } + + // Sends the received line to the server. lastWriteFuture = channel.write(line + '\n'); + + // If user typed the 'bye' command, wait until the server closes + // the connection. + if (line.toLowerCase().equals("bye")) { + channel.getCloseFuture().awaitUninterruptibly(); + break; + } } // Wait until all messages are flushed before closing the channel. diff --git a/src/main/java/org/jboss/netty/example/telnet/TelnetClient.java b/src/main/java/org/jboss/netty/example/telnet/TelnetClient.java index 7fe087d141..e156854168 100644 --- a/src/main/java/org/jboss/netty/example/telnet/TelnetClient.java +++ b/src/main/java/org/jboss/netty/example/telnet/TelnetClient.java @@ -91,6 +91,13 @@ public class TelnetClient { // Sends the received line to the server. lastWriteFuture = channel.write(line + '\n'); + + // If user typed the 'bye' command, wait until the server closes + // the connection. + if (line.toLowerCase().equals("bye")) { + channel.getCloseFuture().awaitUninterruptibly(); + break; + } } // Wait until all messages are flushed before closing the channel.