Why do I get UDP datagrams out of order even with processes running locally?

て烟熏妆下的殇ゞ 提交于 2019-11-28 01:49:43

Actually there are no guarantees of ordering and reception about UDP packets, even if they are sent by localhost on localhost. Just because the specification of the protocol doesn't imply anything about it.

Since you can't make assumptions on them you should choose to use TCP or handle reordering by using a sequence number handled by your programs..

This would be operating system dependent. While you failed to specify an operating system it isn't important anyway. To remain portable you should always anticipate your datagram sockets receiving out of order data.

Although you are running localhost, expect UDP datagrams to be out of sequence in actual deployment.

If you need them in sequence, try TCP.

UDP isn't specified to preserve sequence, as the posters above have all said, but if there are no intermediate routers I would also suspect a bug in your code.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!