【问题标题】:Netty cannot send second request in a channelNetty 无法在通道中发送第二个请求
【发布时间】:2019-09-25 14:43:03
【问题描述】:

我尝试在 netty 中模拟 http 握手,但客户端无法发送第二个请求。 这是流程

Client -> request1 -> Server
Client <- response <- server
Client -> request2 -> Server (cannot see data is sent)
Client <- response <- server

这里是代码 https://github.com/Tonghua-Li/Netty-Handshake-Test/tree/master/src/main/java

服务器和客户端日志位于 git repo 的根文件夹中 https://github.com/Tonghua-Li/Netty-Handshake-Test/blob/master/client.log

从日志中,请求 2 已准备好并刷新到端口 80(服务器)。但我在客户端日志中没有看到作为请求 1 的十六进制块

sending request 2
Sep 24, 2019 6:02:40 PM io.netty.handler.logging.LoggingHandler flush
INFO: [id: 0xd6797f27, L:/127.0.0.1:60893 - R:/127.0.0.1:80] FLUSH

谢谢!

【问题讨论】:

    标签: java netty


    【解决方案1】:

    您需要创建FullHttpRequest 实例,或者您需要在发送下一个HttpRequest 之前使用LastHttpRequest“终止”您的HttpRequest

    如果您将ChannelFutureListener 附加到writeAndFlush(...) 返回的ChannelFuture,您将看到ChannelFuture 失败,因为“消息序列”不是预期的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-16
      • 1970-01-01
      • 1970-01-01
      • 2016-01-25
      • 2013-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多