[null, null, {"document_url": "https://16bpp.net/tutorials/csharp-networking/06b", "unformatted_src": "https://storage.googleapis.com/sixteenbpp/tutorials/images/udp-file-transfer-protocol-diagram.png", "src": "https://storage.googleapis.com/sixteenbpp/tutorials/images/udp-file-transfer-protocol-diagram.png", "formatted_filename": "udp file transfer protocol diagram", "alt_text": "UDP File Transfer Diagram", "rendered_width": 1000, "rendered_height": 1608}, null, null]
UDP File Transfer - Protocol Design 
This protocol is going to be a bit complex.  Since UDP doesn't have ACKs built in, we're going to have to add them manually.  Not every type of message with have an ACK, just some control ones.  The Packet class (code in next part), contains two fields, PacketType (control) and Payload (data).  For each type, the data in Payload will be structured differently.


File data will be transferred in Blocks.  They have simply two fields, an unsigned 32 bit integer that is it's ID Number, and a byte array that is the contained Data.  Typically the Data in the Block is compressed.  The code for this class is in the next part.

Packet Types

These are used to tell our app what each datagram is supposed to mean, they are:

Here is a helpful diagram that explains how the exchanges work: Packet Data (Payloads)

Here's the data that some exchanges should contain.

If you are confused, take a look at the diagram as it has some examples: