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

4

15

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

Lissalissak answered 28/3, 2010 at 17:51 Comment(1)
That's a good question, i'm also interested in possible causes of this.Lifegiving
D
7

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

Dorisdorisa answered 28/3, 2010 at 18:13 Comment(0)
P
8

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.

Pimiento answered 28/3, 2010 at 17:56 Comment(0)
D
7

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

Dorisdorisa answered 28/3, 2010 at 18:13 Comment(0)
D
1

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

If you need them in sequence, try TCP.

Dorisdorisa answered 28/3, 2010 at 18:9 Comment(0)
A
1

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.

Assessor answered 29/3, 2010 at 7:10 Comment(4)
Nah. It's likely due to multiprocessor packet handling.Heliport
Wow, just noticed this comment. You didn't tag my name, so no notification. Anyway: operating systems that speed up packet handling by spreading the work to multiple cores may have processed the UDP packets on different cores and placed them into the application read queue out of order.Heliport
More food for thought, TCP can have the same problem Zan is talking about. If more than one thread is handling sending data, data may be transmitted in a different order than you wrote.Webber
Zan's comment is actually better than any of the answers; it's the only thing here that even gives a possible explanation of the question, which was WHY it was happening.Collegium

© 2022 - 2024 — McMap. All rights reserved.