//public override void ChannelActive(IChannelHandlerContext context) // => context.WriteAndFlushAsync(new Request() { Code = 1, Body = Encoding.UTF8.GetBytes("ping") }); public override void ChannelRead(IChannelHandlerContext context, object message) { if (message != null) { var request = message as Request; _messageBox.AddAsync(request).Wait(); _logger.Info("Received from server: " + Encoding.UTF8.GetString(request.Body)); } }
//public override void ChannelActive(IChannelHandlerContext context) // => context.WriteAndFlushAsync(new Request() { Code = 1, Body = Encoding.UTF8.GetBytes("ping") }); public override void ChannelRead(IChannelHandlerContext context, object message) { if (message == null) { _logger.Info("message content is null."); return; } if (message is Request request) { _messageBox.AddAsync(request).Wait(); _logger.Info("Received from server: " + request.Body.ToStringUtf8()); } else { _logger.Warn($"message type[{message.GetType().FullName}] not match Request[{typeof(Request).FullName}]"); } }