我有一台在 Netty 上工作的服务器。客户端发送一些握手消息和服务器回复。这些是小消息,这些没有问题。
但是,当服务器尝试发送一些大消息(每个大小为 131139 字节)时,似乎它们正在被发送ChannelFuture
,isSuccess()
返回true
和getCause()
返回null
。但是,客户端永远不会得到完整的消息,只有第一4097
条消息的第一个字节。在 4 或 5 条消息之后,netty 停止尝试发送新消息。
我isWritable()
在发送消息之前正在阅读频道(它总是返回true
)。仅当 的 被触发时才会尝试下一条operationComplete
消息ChannelFutureListener
。将消息写入通道后,日志显示“INTEREST_CHANGED”事件被抛出两次,并且isWritable
更改为false
,然后立即更改为true
。但是消息永远不会到达客户端。
INFO [New I/O worker #7] (HashSender.java:33) - Attempting send a message: 0
INFO [New I/O worker #7] (HashSender.java:68) - Is channel writable: true
INFO [New I/O worker #7] (FrameLengthPrepender.java:46) - outgoing packet lenght: 131139
INFO [New I/O worker #7] (ClientHandler.java:32) - [id: 0xdbb48b90, /192.168.0.3:60105 => /192.168.0.4:25025] INTEREST_CHANGED
INFO [New I/O worker #7] (ClientHandler.java:33) - Is channel writable: true
INFO [New I/O worker #7] (HashSender.java:16) - Message Successfully sent. Channel isDone: true, success: true, cancelled: false, error: null
INFO [New I/O worker #7] (HashSender.java:33) - Attempting send a message: 1
INFO [New I/O worker #7] (HashSender.java:68) - Is channel writable: true
INFO [New I/O worker #7] (FrameLengthPrepender.java:46) - outgoing packet lenght: 131139
INFO [New I/O worker #7] (ClientHandler.java:32) - [id: 0xdbb48b90, /192.168.0.3:60105 => /192.168.0.4:25025] INTEREST_CHANGED
INFO [New I/O worker #7] (ClientHandler.java:33) - Is channel writable: false
INFO [New I/O worker #7] (ClientHandler.java:32) - [id: 0xdbb48b90, /192.168.0.3:60105 => /192.168.0.4:25025] INTEREST_CHANGED
INFO [New I/O worker #7] (ClientHandler.java:33) - Is channel writable: true
INFO [New I/O worker #7] (HashSender.java:16) - Message Successfully sent. Channel isDone: true, success: true, cancelled: false, error: null
INFO [New I/O worker #7] (HashSender.java:33) - Attempting send a message: 2
INFO [New I/O worker #7] (HashSender.java:68) - Is channel writable: true
INFO [New I/O worker #7] (FrameLengthPrepender.java:46) - outgoing packet lenght: 131139
INFO [New I/O worker #7] (ClientHandler.java:32) - [id: 0xdbb48b90, /192.168.0.3:60105 => /192.168.0.4:25025] INTEREST_CHANGED
INFO [New I/O worker #7] (ClientHandler.java:33) - Is channel writable: false
INFO [New I/O worker #7] (ClientHandler.java:32) - [id: 0xdbb48b90, /192.168.0.3:60105 => /192.168.0.4:25025] INTEREST_CHANGED
INFO [New I/O worker #7] (ClientHandler.java:33) - Is channel writable: true
INFO [New I/O worker #7] (HashSender.java:16) - Message Successfully sent. Channel isDone: true, success: true, cancelled: false, error: null
INFO [New I/O worker #7] (HashSender.java:33) - Attempting send a message: 3
INFO [New I/O worker #7] (HashSender.java:68) - Is channel writable: true
INFO [New I/O worker #7] (FrameLengthPrepender.java:46) - outgoing packet lenght: 131139
INFO [New I/O worker #7] (ClientHandler.java:32) - [id: 0xdbb48b90, /192.168.0.3:60105 => /192.168.0.4:25025] INTEREST_CHANGED
INFO [New I/O worker #7] (ClientHandler.java:33) - Is channel writable: false
INFO [New I/O worker #7] (ClientHandler.java:32) - [id: 0xdbb48b90, /192.168.0.3:60105 => /192.168.0.4:25025] INTEREST_CHANGED
INFO [New I/O worker #7] (ClientHandler.java:33) - Is channel writable: true
INFO [New I/O worker #7] (HashSender.java:16) - Message Successfully sent. Channel isDone: true, success: true, cancelled: false, error: null
INFO [New I/O worker #7] (HashSender.java:33) - Attempting send a message: 4
INFO [New I/O worker #7] (HashSender.java:68) - Is channel writable: true
INFO [New I/O worker #7] (FrameLengthPrepender.java:46) - outgoing packet lenght: 131139
INFO [New I/O worker #7] (ClientHandler.java:32) - [id: 0xdbb48b90, /192.168.0.3:60105 => /192.168.0.4:25025] INTEREST_CHANGED
INFO [New I/O worker #7] (ClientHandler.java:33) - Is channel writable: false
INFO [New I/O worker #7] (ClientHandler.java:32) - [id: 0xdbb48b90, /192.168.0.3:60105 => /192.168.0.4:25025] INTEREST_CHANGED
INFO [New I/O worker #7] (ClientHandler.java:33) - Is channel writable: true
INFO [New I/O worker #7] (HashSender.java:16) - Message Successfully sent. Channel isDone: true, success: true, cancelled: false, error: null
INFO [New I/O worker #7] (HashSender.java:33) - Attempting send a message: 5
INFO [New I/O worker #7] (HashSender.java:68) - Is channel writable: true
INFO [New I/O worker #7] (FrameLengthPrepender.java:46) - outgoing packet lenght: 131139
INFO [New I/O worker #7] (ClientHandler.java:32) - [id: 0xdbb48b90, /192.168.0.3:60105 => /192.168.0.4:25025] INTEREST_CHANGED
INFO [New I/O worker #7] (ClientHandler.java:33) - Is channel writable: false
谁能告诉我为什么消息没有通过?
更新:它实际上是第一条消息的 4097 字节。我没有计算标记数据包长度的前 4 个字节。
更新:如果传出数据包长度小于或等于 4097 字节,则一切正常。仅当数据包大于 4097 字节时,Netty 才会中断。它是 4097,而不是 4096。它会响铃吗?