【发布时间】:2017-03-04 20:58:33
【问题描述】:
我使用http://netty.io/wiki/user-guide-for-4.x.html 链接编写了一个netty 服务器。但我得到的数据最多只有 16384 字节。
public class DiscardServerHandler extends ChannelInboundHandlerAdapter
{
byte bNullArray[] = "".getBytes();
String strFullData= new String(bNullArray,StandardCharsets.UTF_8);
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
{
try
{
String MsgRead;
ByteBuf in = (ByteBuf) msg;
MsgRead=in.toString(io.netty.util.CharsetUtil.UTF_8);
// here I get data only upto 1024 and this method get called 16 times.
// So total data received is == 1024*16 = 16384
strFullData = strFullData + MsgRead;
}
finally
{
ReferenceCountUtil.release(msg);
}
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
{
//WriteMyLog(strFullData);
//Here size of strFullData is 16384
strFullData = ProcessMyData(strFullData);
byte[] respByteBuf = strFullData.getBytes();
ByteBuf Resp1 = ctx.alloc().buffer(respByteBuf.length);
Resp1.writeBytes(respByteBuf);
ctx.write(Resp1);
ctx.flush();
ctx.close();
}
}
如何获取更多数据?
【问题讨论】:
标签: netty