Navin
Navin

Reputation: 534

UDP Packet arrangement

I have implemented a P2P application using Boost C++. As you know, UDP does not guarantee packet order or even packet delivery, so this is what I thought of:

Put all the received UDP packet for one request in a link list and order it correctly so that the sequence and missing packets can be identified in a robust way. The link list is made using struct.

-Or-

I thought putting it in a vector and arranging the packets in the vector in a separate thread.

Which one is the best method? or do you'll have another best method other than window sliding.

Upvotes: 2

Views: 1936

Answers (2)

scai
scai

Reputation: 21529

For ensuring correct order and detect missing packets or duplicates you have to use sequence numbers or a similar approach. How can you check for the correct order on the receiving side when you put your packets in a linked list on the sending side? See the TCP protocol for an example solution on detecting missing and out of order packets (it does a little more, though).

Usually UDP is used when packet loss or reordering is acceptable. If you want to ensure these two properties even for UDP you have to do some work yourself.

Upvotes: 0

Some programmer dude
Some programmer dude

Reputation: 409482

Instead of implementing your own container or sorting, why not use what's already in the standard library?

For example, you could use std::map with the sequence number as key. It's automatically sorted by key.

Or you could use std::priority_queue with your own compare function that checks the sequence number.

You should also look into UPnP NAT traversal.

Upvotes: 6

Related Questions