2个实现ChannelInboundMessageHandlerAdapter的handler为什么一个能打印信息一个不能打印

处理器1:

public class ChatClientHandler1 extends ChannelInboundMessageHandlerAdapter<String> {

    public void messageReceived(ChannelHandlerContext channelHandlerContext, String s) throws Exception {
        System.out.println("ChatClientHandler1>>>>:"+s);
    }
}

处理器2:

public class ChatClientHandler2 extends ChannelInboundMessageHandlerAdapter<String> {

    public void messageReceived(ChannelHandlerContext channelHandlerContext, String s) throws Exception {
        System.out.println("ChatClientHandler>>>>:"+s);
    }
}

public class ChatClientHandlerInitializer extends ChannelInitializer<SocketChannel>{

    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast("framer",new DelimiterBasedFrameDecoder(1024, Delimiters.lineDelimiter()));
        pipeline.addLast("decoder",new StringDecoder(Charset.forName("UTF-8")));
        pipeline.addLast("encoder",new StringEncoder(Charset.forName("UTF-8")));
        pipeline.addLast("handler1",new ChatClientHandler1());
        pipeline.addLast("handler2",new ChatClientHandler2());
    }
}

为什么 ChatClientHandler2 不会打印消息,而 ChatClientHandler1 能正常打印消息??

阅读 1.8k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进