DotNetty客户端获取未编码的16进制数据

 public override void ChannelRead(IChannelHandlerContext context, object message)
 {
     var buffer = message as IByteBuffer;
     Console.WriteLine($"收到消息{buffer}");
     if (buffer != null)
     {
         // 这里可以处理接收到的数据
         byte[] bytes = new byte[buffer.ReadableBytes];
         buffer.ReadBytes(bytes);
         // 转换为十六进制字符串以便显示
         string str = BitConverter.ToString(bytes).Replace(" ", "");
         Console.WriteLine("接收服务端消息: " + str.ToString() + "原始byte:" + bytes);
     }
     context.WriteAsync(message);
     //context.WriteAndFlushAsync(message);
 }

 

posted @ 2024-03-29 09:38  流年sugar  阅读(24)  评论(0编辑  收藏  举报