逻辑就是在处理handler前加入一个处理符,然后
channelReadComplete这个事件进行处理。
同时注意客服端的配置:
1 public void connect(String addr, int port, final String xml, final String key,final boolean flag) throws Exception { 2 EventLoopGroup group = new NioEventLoopGroup(); 3 try { 4 Bootstrap b = new Bootstrap(); 5 b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) 6 .option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(1024*1024))//这行配置比较重要 7 .handler(new ChannelInitializer<SocketChannel>() { 8 protected void initChannel(SocketChannel ch) throws Exception { 9 ChannelPipeline pipeline = ch.pipeline(); 10 pipeline.addLast(new EsbClientHandler(xml, key,flag)); 11 } 12 });