A C implementation of a reliable transport layer built on top of UDP.
This project implements transport-layer reliability mechanisms such as acknowledgements, retransmissions, checksums, ordered delivery, EOF handling, sliding windows, and server-side connection demultiplexing.
UDP does not guarantee reliable delivery, packet ordering, or protection from packet drops/corruption. This project adds a reliability layer over UDP by implementing:
- Packet sequence numbers
- Cumulative acknowledgements
- Checksum-based corruption detection
- Timeout-based retransmission
- Ordered stream delivery
- EOF/connection teardown handling
- Stop-and-wait reliability
- Sliding-window reliability
- Out-of-order packet buffering
- Multiple connection demultiplexing in server mode
.
├── README.md
├── .gitignore
├── stop-and-wait/
│ ├── Makefile
│ ├── reliable.c
│ ├── rlib.c
│ ├── rlib.h
│ └── uc.c
└── sliding-window/
├── Makefile
├── reliable.c
├── rlib.c
├── rlib.h
└── uc.c
Folder:
stop-and-wait/This version supports a single reliable connection between two UDP ports.
Only one data packet is kept outstanding at a time. The sender transmits a packet and waits for its acknowledgement before sending the next packet.
Implemented features:
- Single direct UDP-to-UDP connection
- One outstanding packet at a time
- Packet checksum validation
- Cumulative ACK handling
- Timeout-based retransmission
- EOF packet handling
- In-order stream output
Folder:
sliding-window/This version extends the stop-and-wait implementation with a configurable sliding window and server-side connection demultiplexing.
Implemented features:
- Multiple outstanding packets
- Configurable sender/receiver window size using
-w - Receiver-side buffering for out-of-order packets
- Cumulative acknowledgements
- Timeout-based retransmission of unacknowledged packets
- Multiple client connections in server mode
- TCP-to-reliable-UDP relay mode using the provided
ucutility
This project is intended to be built on a Unix/Linux environment.
Install build tools:
sudo apt update
sudo apt install build-essentialBuild the stop-and-wait version:
cd stop-and-wait
makeBuild the sliding-window version:
cd sliding-window
makeThe build creates the following executables:
reliable
uc
reliable is the reliable UDP transport program.
uc is a small TCP/Unix socket utility used for testing client/server mode.
Some older course framework files may trigger warnings on newer compilers.
If stop-and-wait fails because warnings are treated as errors, build it using:
cd stop-and-wait
make clean
make CFLAGS="-g -Wall"This removes -Werror for the local build.
Open two terminals.
Terminal 1:
cd stop-and-wait
./reliable 6666 localhost:5555Terminal 2:
cd stop-and-wait
./reliable 5555 localhost:6666Now type text in either terminal. It should be delivered to the other terminal through the reliable UDP layer.
To enable debug packet logs:
./reliable -d 6666 localhost:5555Open two terminals.
Terminal 1:
cd sliding-window
./reliable -w 5 6666 localhost:5555Terminal 2:
cd sliding-window
./reliable -w 5 5555 localhost:6666Here, the sender can keep up to 5 packets outstanding before waiting for acknowledgements.
You can try different window sizes:
./reliable -w 1 6666 localhost:5555
./reliable -w 10 6666 localhost:5555A window size of 1 behaves like stop-and-wait.
The sliding-window version also supports client/server mode.
In this mode:
uclistens on a TCP port.- The reliable server receives reliable UDP packets and forwards data to a TCP endpoint.
- The reliable client accepts TCP input and relays it through reliable UDP to the server.
Use four terminals.
Terminal 1: start a TCP listener.
cd sliding-window
./uc -l 2222Terminal 2: start the reliable UDP server.
cd sliding-window
./reliable -s -w 5 1111 localhost:2222Terminal 3: start the reliable UDP client.
cd sliding-window
./reliable -c -w 5 3333 localhost:1111Terminal 4: connect to the client using uc.
cd sliding-window
./uc localhost 3333Now type into Terminal 4. The data flows through:
uc client
-> reliable client
-> reliable UDP transport
-> reliable server
-> uc listener
reliable.c
Contains the main reliable transport implementation.
rlib.c / rlib.h
Provided framework/library code for packet handling, sockets, timers, and connection abstraction.
uc.c
Utility program used to connect/listen on TCP or Unix-domain sockets for testing.
- Transport-layer protocol design
- Reliable communication over unreliable UDP
- Stop-and-wait protocol
- Sliding-window protocol
- Flow control
- Packet retransmission
- Cumulative acknowledgements
- Packet corruption detection
- Out-of-order packet buffering
- Connection demultiplexing
- Socket programming in C
- Systems programming
This project is inspired by Stanford CS144's publicly available Reliable Transport lab.
This repository is not affiliated with, endorsed by, or maintained by Stanford University.
The reliable transport implementation was completed as a personal systems/networking project for learning purposes.