System Architecture
The Selective Repeat UDP project implements a reliable data transfer protocol over UDP using the Selective Repeat ARQ (Automatic Repeat reQuest) mechanism. The system consists of three main components that work together to provide reliable communication over an unreliable network layer.Three-Component Architecture
Client
Initiates connections and sends HTTP-style requests using the reliable protocol
Server
Handles multiple client connections and processes HTTP GET/POST requests
Router
Simulates network conditions with configurable packet loss and delays
Client Component
The client is implemented in Java and consists of two main classes:Httpc(client/Httpc.java) - HTTP client interface that parses commands and formats HTTP requestsReliableClientProtocol(client/ReliableClientProtocol.java) - Implements the Selective Repeat protocol for reliable data transfer
- Establish three-way handshake connections with the server
- Fragment large data into 1013-byte payload chunks
- Maintain a sliding window for transmission (default window size: 100 packets)
- Handle ACK/NACK responses and retransmit lost packets
- Implement timeout-based retransmission with exponential backoff
The client always communicates through the router at
127.0.0.1:3000, which forwards packets to the actual destination.Server Component
The server is implemented in Java with a multi-threaded architecture:ServerTcpProtocl(Server/ServerTcpProtocl.java) - Main server class handling connection handshakesclientHandler- Inner class that processes individual client requests in separate threadsHttpcLib(Server/HttpcLib.java) - HTTP request processor for GET and POST operations
- Listen for connection requests on the main port (default: 8000)
- Create dedicated handler sockets for each unique client
- Implement Selective Repeat protocol for receiving data
- Process HTTP GET/POST requests and serve files from a directory
- Send responses using the same reliable protocol
Router Component
The router is implemented in Go and simulates real-world network conditions:router.go(Router/source/router.go) - Network simulator with configurable parameters
- Receive packets from both clients and servers on port 3000
- Parse packet headers to determine destination
- Simulate packet loss based on configurable drop rate
- Introduce random delays (0 to max-delay) to simulate network latency
- Forward packets to their intended destinations
- Swap peer addresses during routing
Router Parameters:
--port: Listening port (default: 3000)--drop-rate: Probability of packet loss (0.0 to 1.0)--max-delay: Maximum delay for packet delivery (e.g., 10ms, 100ms)--seed: Random seed for reproducible testing
Communication Flow
Key Design Features
1. Sliding Window Protocol
Both client and server maintain a sliding window with:- Window Size: 100 packets (configurable)
- Last ACK Received: Tracks the highest cumulative ACK
- Packet Buffer: Stores unacknowledged packets for retransmission
2. Packet Fragmentation
Large data is split into chunks:- Payload Size: 1013 bytes per packet
- Header Size: 11 bytes (type + sequence + address + port)
- Total Packet Size: Maximum 1024 bytes
3. Timeout and Retransmission
Each packet has an associated timer:- Initial Timeout: 30ms (client) / 30ms (server)
- Maximum Retries: 10 attempts
- Timer Implementation: Separate thread per packet using
Timerclass
4. Thread-Based Concurrency
Client:- Main thread handles sending initial window
- Timer threads for each packet timeout
- Receive thread processes ACK/NACK responses
- Main thread accepts connections
- Handler thread per client
- Timer threads for packet retransmission
- Single goroutine-based event loop
- Time-delayed packet delivery using
time.AfterFunc
Technology Stack
Client
Java
- JDK 8+
- DatagramSocket API
- Multi-threading
Server
Java
- JDK 8+
- HashMap for client tracking
- File I/O operations
Router
Go
- net package
- Goroutines
- Atomic operations
Source Code Structure
Performance Characteristics
Throughput
Throughput
With a window size of 100 packets and 1013-byte payloads:
- Maximum throughput: ~101.3 KB per window
- Effective throughput: Depends on RTT and packet loss rate
- Formula:
Throughput ≈ (WindowSize × PacketSize) / RTT
Latency
Latency
- Minimum RTT: 2 × network delay (client → router → server → router → client)
- Timeout overhead: 30ms per retransmission
- Connection setup: 1.5 RTT (three-way handshake)
Reliability
Reliability
- Guaranteed delivery: Up to 10 retransmission attempts
- In-order delivery: Receiver buffers out-of-order packets
- Flow control: Sliding window prevents receiver overflow
Next Steps
Selective Repeat Protocol
Learn about the detailed implementation of the SR-ARQ protocol
Packet Structure
Understand the packet format and header fields