处理器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 能正常打印消息??