Packet integrity with UDP ?

Blitz3D Forums/Blitz3D Beginners Area/Packet integrity with UDP ?

RemiD(Posted 2013) [#1]
Hello,

I am trying to code some routines to manage packets transfer between 3 client programs and 1 server program.

For now each packet is composed of :
PacketSize (short)
PacketKind (byte)
PacketId (int)
Datas

PacketSize is the total size in bytes after having written the packet with all the datas.

PacketKind is the kind of the packet, it can be Datas or Message and explains to the other program how to read the packet.

PacketId is the id of the packet so the program knows in which order to use the packet.

Do you think that to include the size of the packet (in bytes) is necessary ?
If a packet is received by a program with the command RecvUDPMsg(), is it always intact or can it sometimes be corrupted ?

Thanks,


Matty(Posted 2013) [#2]
Packets arrive intact but not necessarily in order


RemiD(Posted 2013) [#3]
Thanks for the info Matty, :) i will remove the variable PacketSize.


MCP(Posted 2013) [#4]
Packets arrive intact but not necessarily in order

Sorry Matty that answer seems pretty vague to me and can leave false assumptions as to the reliability of UDP packet transfers. Are you saying all UDP packets will arrive intact but not necessarily in order, or just those packets that do arrive will be intact but not necessarily in order?


RemiD(Posted 2013) [#5]
From what i have read recently :
With UDP, a packet must have a specific minimum size and maximum size depending on the temporary memory of routers it will go through.

So in order to avoid that the packet will become stuck, the UDP will automatically split a big packet in several subpackets.

The maximum size being 576bytes or 1500bytes (not sure about this)

See : http://en.wikipedia.org/wiki/Maximum_transmission_unit

But ! Because some subpackets may not use the same road to reach the destination, some subpackets may become lost.

If a subpacket becomes lost, the whole packet will be considered as lost. (probably after a specific time ?)

If all subpackets manage to reach the destination, the whole packet will be considered as received and can be read.

So in theory there is no need to add the size of the packet in the packet because it is already done by the UDP.

About the order, because some packets may use a longer road than others to reach the destination, an old packet may be received after a recent packet, this is why you can't rely on the order that the packets are received, you must add an Id to each packet. And i will go further, you must also add a Kind /Type to each packet so that you know how to read it depending on if it is a simple message/notification or if it is datas.

This is only my understanding, please correct what you think is false.


MCP(Posted 2013) [#6]
An interesting link RemiD. Thanks. BTW I'm not exactly an expert on the subject either (and don't claim to be!) which is why I asked Matty to clarify his response to your original post as it seems a little ambiguous (to me anyway!)