为什么在client调用ctx.channel().close()后触发sever-side channelReadComplete以及如何防止

问题描述 投票:0回答:0

我有一个netty server和一个netty client,当server收到client的消息时,channelReadComplete会被触发一次,对我来说,这是合理的,然后client收到了server的消息,client在调用

ctx.channel().close()
channelRead
方法关闭与服务端的连接,此时服务端会再次触发
channelReadComplete
调用,但客户端并没有实际发送业务数据。我在一些帖子中注意到我可以在 SocketChannel 配置中将
autoRead
设置为 false 并手动调用
ChannelHandlerContext.read()
来解决它,但我想将
autoRead
保留为默认值 true 以最小化对应用程序的更改。那么我如何在不将 autoRead 设置为 true 的情况下解决这个问题,以及当
ctx.channel().close()
被调用时 netty 框架内部到底发生了什么?

netty
© www.soinside.com 2019 - 2024. All rights reserved.