使用 java nio 在长传送路径上丢失消息

发布于 2024-11-14 15:13:46 字数 268 浏览 2 评论 0原文

在我的项目中,一系列消息从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国粹 2024-11-21 15:13:46

我通过检查写入的字节数解决了这个问题。如果写了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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文