2017-07-04 120 views
-1

我做了一个骆驼netty4服务器程序。客户端发送1119字节的消息,但我的解码器截断1024/95骆驼netty4消息1024截断..如何解决它?

这里是我的代码。

@ChannelHandler.Sharable 
    public static class BytesDecoder extends MessageToMessageDecoder<ByteBuf> { 

     @Override 
     protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { 
        System.out.println("BytesDecoder readableBytes:"+msg.readableBytes()); 
      if (msg.isReadable()) { 
       byte[] bytes = new byte[msg.readableBytes()]; 
       int readerIndex = msg.readerIndex(); 
       msg.getBytes(readerIndex, bytes); 
       out.add(bytes); 
      } 
     } 

    } 

结果===>

BytesDecoder readableBytes:1024

BytesDecoder readableBytes:95

我希望得到一个完整的邮件字节1119字节。

+0

检查有关这些编解码器的netty文档,它们很可能具有1024的默认限制,您需要重新配置为更高的值等。 –

回答

0

其实我已经在netty邮件列表上回答了这个问题。

我们不保证您会在一次阅读电话中收到所有数据。因此,您需要通过扩展ByteToMessageDecoder来解决此问题,并且只有在至少有1024个可读的字节时才读取字节。

有关更多示例和详细信息,请参阅ByteToMessageDecoder的javadocs。

+0

Thanks.and you can show your source tip。我无法阅读邮件列表。 Pz我没有足够的时间 – james

+0

我使用ByteToMessageDecoder创建此代码顺便说一句如何处理我的动态data.i无法识别的可读性大小。 – james