Open bhwbgy opened 5 years ago
IByteBuffer imsg = (IByteBuffer)msg; byte[] result = new byte[imsg.ReadableBytes]; imsg.ReadBytes(result); When your data is greater than 1KB, you need to set bootstrap.ChildOption(ChannelOption.RcvbufAllocator,new AdaptiveRecvByteBufAllocator(64,1048,65536));
bootstrap
.Option(ChannelOption.SoBacklog, 100)
.Handler(new LoggingHandler("SRV-LSTN"))
.ChildOption(ChannelOption.RcvbufAllocator, new AdaptiveRecvByteBufAllocator(64, 1048, 65536))
.ChildHandler(new ActionChannelInitializer<IChannel>(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
pipeline.AddLast(new LoggingHandler("SRV-CONN"));
pipeline.AddLast("framing-enc", new LengthFieldPrepender(2));
pipeline.AddLast("framing-dec", new LineBasedFrameDecoder(1200));
//pipeline.AddLast("framing-dec", new LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2));
//pipeline.AddLast("heart", new IdleStateHandler(0, 0, 3000 / 1000));
pipeline.AddLast("echo", new NettyTcpByteHandler());
}));
//dt1 = DateTime.Now;
IChannel boundChannel = await bootstrap.BindAsync(int.Parse(ConfigurationManager.AppSettings["nettyTCPPort"]));
I set the bootstrap like this,but i still can't get the data correctly.I use other device to send the data 80 ms once.
I want to get a data by dotnetty,but the data's type is byte,how can i get the data?I used IByteBuffer.Array to transform the data to byte[],but the result lost some bytes.