title: Netty channelRead never called
body: <p>I've played a bit with netty and followed a video(<a href="https://www.youtube.com/watch?v=tsz-assb1X8" rel="nofollow">https://www.youtube.com/watch?v=tsz-assb1X8</a>) to build a chat server and client the server works properly(I tested with telnet and here it works) but the client does not recives data. The channelRead method in ChatClinetHandler.java were never called but the channelReadComplete were called.</p>
  
  <p>ChatClient.java</p>
  
  <pre><code>import io.netty.bootstrap.Bootstrap;
  import io.netty.channel.Channel;
  import io.netty.channel.EventLoopGroup;
  import io.netty.channel.nio.NioEventLoopGroup;
  import io.netty.channel.socket.nio.NioSocketChannel;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.net.InetSocketAddress;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  public class ChatClient {
  
      public static void main(String args[]) {
          try {
              new ChatClient(new InetSocketAddress("localhost", 8000)).run();
          } catch (Exception ex) {
              Logger.getLogger(ChatClient.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
      private final InetSocketAddress server;
  
      public ChatClient(InetSocketAddress server) {
          this.server = server;
      }
  
      public void run() throws Exception {
          EventLoopGroup group = new NioEventLoopGroup();
          try {
              Bootstrap bootstrap = new Bootstrap()
                      .group(group)
                      .channel(NioSocketChannel.class)
                      .handler(new ChatClientInitializer());
  
              Channel channel = bootstrap.connect(server).sync().channel();
              System.out.println("Connected to Server: " + server.toString());
              BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
              while (channel.isActive()) {
                  String userMessage = in.readLine();
                  channel.writeAndFlush(userMessage + "\r\n");
                  if (userMessage.equalsIgnoreCase("bye")) {
                        group.shutdownGracefully();
                        break;
                  }
  
              }
          } finally {
              group.shutdownGracefully();
          }
      }
  }
  </code></pre>
  
  <p>ChatClientInitializer.java</p>
  
  <pre><code>import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.DelimiterBasedFrameDecoder; import io.netty.handler.codec.Delimiters; import io.netty.handler.codec.string.StringDecoder; import io.netty.handler.codec.string.StringEncoder;
  
  public class ChatClientInitializer extends ChannelInitializer&lt;SocketChannel&gt; {
  
      @Override
      protected void initChannel(SocketChannel c) throws Exception {
          ChannelPipeline pipeline = c.pipeline();
          pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
          pipeline.addLast(new StringDecoder());
          pipeline.addLast(new StringEncoder());
          pipeline.addLast(new ChatClientHandler());
      } }
  </code></pre>
  
  <p>ChatClinetHandler.java</p>
  
  <pre><code>import io.netty.channel.ChannelHandlerContext;
  import io.netty.channel.ChannelInboundHandlerAdapter;
  
  
  public class ChatClientHandler extends ChannelInboundHandlerAdapter {
      @Override
      public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
          System.out.println(msg.toString());
      }
  
      @Override
      public void exceptionCaught(ChannelHandlerContext ctx,
              Throwable cause) {
          cause.printStackTrace();
      }
  
  }
  </code></pre>