Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

upd does not get disordered

I am sending udp packets to the port 7
of a remote host and the packets are returned in the same order they were
Could you send to me a code in C with
2 threads (sender and receiver)in wich
the packets get disordered?

  • 2
1 Solution
Well, it looks to me that UDP does not *guarantee* that packets will be received in the order they are sent. But it does not guarantee the opposite either.

This means you cannot rely on the packet (dis)ordering either way. (As a matter of fact you cannot even assume that packets are actually delivered, unless somehow acknowledged)

The reasons packets (TCP or UDP) can get out of order are plentiful but they are dependent on the network paths and conditions, not on their specific treatment at the sending/receiving side. (For instance packets can be processed by different routers and travel through different network segments).
In my opinion, you will seldom (if ever) witness such an occurence on your standard LAN.

UDP differs from TCP in that while a conscious effort is made to reorder out-of-order TCP packets (using sequence numbers) no such action is taken for UDP. OTOH no effort is made to scramble UDP packet ordering, either.

HTH & cheers,
What alf told is correct.
That basically depends on where your server and client are located in LAN. I think your LAN could be small and you may have few paths from server to client. More over there really may not be much delay in two paths. That is why you are receiving the packets in the same order.
try to put your client and server in a big LAN where many paths exists and network trafic is more, then you will see the dis order of the packets.
Bt I have seen many times dis order of packets.
jjescriAuthor Commented:
My server in Spain (Europe) and my client is in USA.

This does in no way guarantee that your
packets do in fact take different  network paths. It is in fact extremely
likely that (during the same session) the path taken by your packets do not change. (Try traceroute at a few seconds interval  - does the sequence of gateways change?)

I may be mistaken, but in the IP world, the only way for a (short) session (of course UDP does not have sessions, but let's assume a figure of speech) to be variably routed is that one of the routers receives a routing update which actualy changes its idea of best route while the session is in progress - this should be a rare event. Alternatively, you could be traversing a router that does dynamic load balancing during a moment of congestion, or an above-CIR frame relay segment (this would drop some of the packets).

Another (hypothetical) possibility, is if you send packets of different sizes and end up traversing a router that gives a higher priority to shorter packets (does anybody know of routers beahving this way? I'd be curious).

If nothing like this happens, and your packets travel down the cable in the order you send, then I see no way they could be scrambled. Of course, you could differently source route your packets, but, these days, everybody drops source routed packets.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now