This project implements a robust, unidirectional file transfer system over UDP. Designed to overcome the unreliability of connectionless protocols without the overhead of TCP retransmission, this application utilizes Forward Error Correction (FEC) principles (specifically Erasure Coding via libpar2) to ensure data integrity.
The sender slices a file, generates redundancy packets (repair blocks), and transmits them alongside the data. The receiver uses multi-threading to listen on multiple ports, capturing data and redundancy information simultaneously. If packets are lost during transmission, the receiver reconstructs the original file using the redundancy blocks.
- Erasure Coding / FEC: Uses
par2(Reed-Solomon codes) to generate redundancy data, allowing file recovery even with significant packet loss. - Multi-threaded Receiver: Implements
pthreadto listen concurrently on distinct ports for Data, Redundancy, and Control signals. - Custom Application Layer Protocol: Defines a specific packet structure including File ID, Size, Part Number, and Payload.
- Integrity Verification: Automated SHA-256 checksum validation upon transfer completion.
- Non-blocking I/O: Utilizes
select()for efficient socket handling and timeout management. - Sparse File Handling: Uses
lseekto write data out-of-order at correct offsets, handling packet reordering naturally.
To handle fragmentation and reordering, the application wraps data in a custom 1472-byte UDP packet (max payload to fit within standard Ethernet MTU):
| Field | Size | Description |
|---|---|---|
| File ID | 100 bytes | Unique identifier/filename |
| File Size | 8 bytes | Total size of the file |
| Part Number | 8 bytes | Index of the current chunk |
| Data | 1356 bytes | Actual file content |
The system utilizes three UDP ports starting from a base port P:
- Port P (Data Channel): Transmits the actual chunks of the source file.
- Port P+1 (Redundancy Channel): Transmits
.par2recovery files generated based on the user-specified redundancy percentage. - Port P+2 (Control/Integrity Channel): Transmits the SHA-256 hash and a "Finalization" signal.
The project relies on standard Linux libraries and specific command-line tools for mathematical operations.
- OS: Linux
- Compiler: GCC
- Dependencies:
libpar2(command line toolpar2must be installed)shasum(part ofperl-digest-shaor coreutils)
# Ubuntu/Debian
sudo apt-get install par2 shasum build-essentialgcc sender.c -o sender
gcc receiver.c -o receiver -pthread# Syntax: ./receiver <PORT>
./receiver 4555# Syntax: ./sender <FILE_PATH> <REDUNDANCY_%> <IP_ADDRESS> <PORT>
./sender my_large_video.mp4 10 127.0.0.1 4555Redundancy %: The percentage of extra data to generate (e.g., 10 means 10% overhead). Higher values allow recovery from higher packet loss rates.
This project was developed as a study on reliable data transfer protocols over unreliable networks using Forward Error Correction.