开发者

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

开发者 https://www.devze.com 2022-12-24 05:04 出处:网络
I\'m developing a java interface between a streaming server and a flash client. I noticed that UDP datagrams can reach my interface out of order even if both processes are running locally.

I'm developing a java interface between a streaming server and a flash client. I noticed that UDP datagrams can reach my interface out of order even if both processes are running locally.

Is that normal? I thought that as no datagram has to go through any router or any network device, then that should not be happeni开发者_运维百科ng.


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.


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..


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号