DotNetty icon indicating copy to clipboard operation
DotNetty copied to clipboard

How to get a data of type byte[]

Open bhwbgy opened this issue 6 years ago • 2 comments
trafficstars

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.

bhwbgy avatar Dec 19 '18 05:12 bhwbgy

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));

491134648 avatar Dec 19 '18 05:12 491134648

            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.

bhwbgy avatar Dec 19 '18 06:12 bhwbgy