Skip to main content

Welcome to Selective Repeat UDP

Selective Repeat UDP is a robust implementation of HTTP over UDP that provides reliable data transfer using the Selective Repeat Automatic Repeat reQuest (ARQ) protocol. This project demonstrates how to build a reliable transport layer on top of the unreliable UDP protocol, making it suitable for applications that require guaranteed delivery without the overhead of TCP.

What is Selective Repeat ARQ?

Selective Repeat is a sliding window protocol that allows the sender to transmit multiple packets without waiting for individual acknowledgments. Unlike Go-Back-N, Selective Repeat retransmits only those packets that are suspected to be lost or corrupted, making it more efficient in networks with higher error rates.

HTTP Client (httpc)

A curl-like HTTP client that sends GET and POST requests over UDP with reliable delivery guarantees

HTTP File Server (httpfs)

A file server that handles HTTP requests over UDP, supporting file retrieval and storage operations

Network Router

A simulated network router written in Go that introduces realistic network conditions for testing

Reliable Protocol

Custom protocol implementation with windowing, acknowledgments, timeouts, and retransmission logic

Key Features

Reliable Data Transfer

The implementation ensures reliable data transfer over UDP through:
  • Selective Repeat ARQ: Only lost packets are retransmitted, not the entire window
  • Sliding Window Protocol: Window size of 100 packets for efficient throughput
  • Sequence Numbers: Each packet is uniquely identified for proper ordering
  • Acknowledgments & NACKs: Positive acknowledgments (ACK) for received packets and negative acknowledgments (NACK) for missing packets

Three-Way Handshake

Connection establishment follows a TCP-like three-way handshake:
// SYN packet (type 2)
Packet syn = new Packet.Builder()
    .setType(2)
    .setSequenceNumber(1L)
    .setPortNumber(serverAddr.getPort())
    .setPeerAddress(serverAddr.getAddress())
    .setPayload("1".getBytes())
    .create();

// SYN-ACK received (type 3)
// ACK sent (type 1)

Packet Structure

Each packet contains the following fields:
Packets have a minimum length of 11 bytes and maximum length of 1035 bytes (11 byte header + 1024 byte payload)
FieldSizeDescription
Type1 bytePacket type (0=Data, 1=ACK, 2=SYN, 3=SYN-ACK, 4=NACK, 6=FIN)
Sequence Number4 bytesPacket sequence number
Peer Address4 bytesIPv4 address
Peer Port2 bytesPort number
Payload0-1024 bytesData payload

HTTP Over UDP Protocol

The project implements a custom HTTP variant called HTTPFC/1.0 that works over the reliable UDP layer:
// Example HTTP GET request format
GET /file.txt HTTPFC/1.0
Host: example.com
User-Agent: httpc/1.0

Advanced Features

Automatic Retransmission

Packets are automatically retransmitted if acknowledgment is not received within the timeout period (50ms)

Out-of-Order Handling

The receiver buffers out-of-order packets and sends NACKs for missing packets to trigger selective retransmission

Flow Control

Sliding window mechanism prevents sender from overwhelming the receiver

Connection Management

Proper connection setup and teardown with SYN/FIN packets

Architecture Overview

The system consists of three main components:
  1. Client (Java): Implements the HTTP client with reliable UDP protocol
  2. Server (Java): File server that responds to HTTP requests over UDP
  3. Router (Go): Simulates network conditions including packet loss, delays, and reordering

Protocol Flow Example

Here’s how a typical request-response flow works:
1

Connection Establishment

Client sends SYN packet to server, receives SYN-ACK, and sends ACK to complete handshake
2

Data Transmission Setup

Client sends a packet indicating the total number of packets to be sent
3

Windowed Data Transfer

Client sends up to 100 packets (window size) without waiting for acknowledgments
4

Selective Acknowledgment

Server sends ACKs for received packets and NACKs for missing packets
5

Selective Retransmission

Client retransmits only the packets that were NACKed or timed out
6

Window Sliding

As packets are acknowledged, the window slides forward allowing more packets to be sent
7

Response Reception

Server sends response data using the same reliable protocol
8

Connection Termination

Server sends FIN packet to close the connection
This implementation is designed for educational purposes to demonstrate reliable transport protocols. For production use, consider standard protocols like TCP or QUIC.

Use Cases

This project is ideal for:
  • Learning: Understanding how reliable transport protocols work at a fundamental level
  • Network Research: Experimenting with ARQ protocols and network conditions
  • Protocol Development: Building custom protocols on top of UDP
  • Testing: Simulating unreliable networks for application testing

Next Steps

Quickstart Guide

Get up and running with the client and server in minutes

Architecture Overview

Learn about the system architecture and components

Build docs developers (and LLMs) love