Reliable Files Transfer

The source code and some specifications will be omitted per UCSC’s policy.

During the Winter 2025, I had a chance to take a network programming class of CSE156. One of my favorite’s class assignments was to create a program transferring files over UDP socket. The goal was to learn the importance and the reason why each TCP field exists, since the assignment forced me to basically reimplement a reliable protocol over unreliable transport link from scratch. The result was a packet structure that is similar to TCP packets, and control flows that assembled TCP.

Challenges

link

Stack

link

C++ with standard library only. Writing on UDP must be done on socket-level only.

Implementation

link

There are two abstraction layers.

           CLIENT                               SERVER
             |                                     ^
      filename,content                      filename,content
             v                                     |
    +-----------------+                   +-----------------+
    |   ReliableFTP   |                   |   ReliableFTP   |
    +-----------------+                   +-----------------+
             |                                     ^
      std::vector<char>                     std::vector<char>
             v                                     |
    +-----------------+                   +-----------------+
    |   ReliableUDP   |                   |   ReliableUDP   |
    +-----------------+                   +-----------------+
             |                                     ^
      std::vector<char>                     std::vector<char>
             v                                     |
+---------------------------------------------------------------+
|                              UDP                              |
+---------------------------------------------------------------+

This one breaks up files to bytes, and vice versa.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SIZE:int(4B)  |          FILENAME:string(SIZE B)              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                     CONTENT:vector<char>                      |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

This layer forms bytes to packets. Metadata (SNI/TYPE) is used for self-made reliable transfer protocol.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     SNI:int(4B)     |     SIZE:int(4B)       |  TYPE:char(1B) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                     CONTENT:vector<char>                      |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

To handle the incoming packets, there must be a concrete algorithm resembling data with the assumption of abnormal sequence. The methods will be left out as this is the heart of the assignment.

Additional notes

link

Not only did I learn more on socket programming and TCP, I also learned how to handle buffers. With many layers of abstraction and fragmentation from limited packet size, constructing partially complete buffer with interactiveness is a must.