好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

过长内容分成了多次发送 问题 LengthFieldBasedFrameDecoder使用

            public ChannelPipeline getPipeline()  throws Exception {               ChannelPipeline pipeline =  new DefaultChannelPipeline();               pipeline.addFirst( "decoder",  new LengthFieldBasedFrameDecoder( 100000000, 0, 4, 0, 4));               pipeline.addLast( "handler",  new XXX(config));                return pipeline;              }          });  

 

 

使用LengthFieldBasedFrameDecoder作为decoder实现,LengthFieldBasedFrameDecoder构造函数,第一个参数为信息最大长度,超过这个长度回报异常,第二参数为长度属性的起始(偏移)位,我们的协议中长度是0到第3个字节,所以这里写0,第三个参数为[长度属性]的长度,我们是4个字节,所以写4,第四个参数为长度调节值,在总长被定义为包含包头长度时,修正信息长度,第五个参数为跳过的字节数,根据需要我们跳过前4个字节,以便接收端直接接受到不含[长度属性]的内容。

 

至此,接收端会按照decoder指定的长度接收完整后才会调用handler继续处理信息。

过长内容分成了多次发送 问题 LengthFieldBasedFrameDecoder使用

标签:

查看更多关于过长内容分成了多次发送 问题 LengthFieldBasedFrameDecoder使用的详细内容...

  阅读:26次