使用 java nio 在长传送路径上丢失消息
在我的项目中,一系列消息从A转发到B再到...到K。传递路径是11个节点。套接字是java nio。问题是有些消息丢失并且在最后一个节点没有收到。这个异常的原因是什么?谢谢。
我使用 TCP 并且只使用 java nio 库。例外:例如,在起始节点,发布了 2999 条消息。在结束节点,收到了 2995 条消息。多条消息在传送路径中丢失。
如果我发送消息的速度非常快,例如间隔时间为50毫秒,则丢失消息的数量会增加。
如何调试这个问题?
谢谢。
In my project, a sequence of messages are forwarded from A to B to ... to K. The delivery path is 11 nodes. The socket is java nio. The problem is that some messages are lost and not received at the last node. What is the reason of this exception? Thanks.
I am using TCP and only use java nio library. The exception: for example, at the starting node, there is 2999 messages published. At the ending node, there is 2995 messages received. Several messages are lost along the delivery path.
If I send the message very fast, eg, the interval time is 50 ms, the number of loss messages are increasing.
How to debug this problem?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过检查写入的字节数解决了这个问题。如果写了0字节,我就重写一遍。当字节缓冲区中没有剩余字节时,写入过程结束。
I solve this problem by checking the number of bytes written. If there is 0 byte written, I will rewrite it again. The writing process ends when there is no remaining bytes in the byte buffer.