Skip to main content
This quickstart guide will help you set up and run a complete Selective Repeat UDP system with a client, server, and router.

Prerequisites

Before you begin, ensure you have the following installed:
  • Java 11 or later - Required for client and server
  • Go 1.7 or later - Required for the router
  • Maven - For building Java components

Setup the Router

The router simulates network conditions and forwards packets between client and server.
cd Router/linux
chmod +x router_x64
./router_x64 --port=3000 --drop-rate=0.1 --max-delay=10ms
The router will listen on port 3000 by default. The --drop-rate=0.1 simulates 10% packet loss, and --max-delay=10ms adds up to 10ms of random delay.

Running the Server

Open a new terminal and start the server:
1

Build the Server

cd Server
mvn clean package
2

Run the Server

Start the server program:
java -cp target/classes Server.ServerCommand
When prompted, enter the server command:
httpfs -v -p 8080 -d ./data
Parameters:
  • -v - Verbose mode (shows detailed logging)
  • -p 8080 - Server listens on port 8080 (default)
  • -d ./data - Directory for file storage (default is current directory)
3

Verify Server is Running

You should see output indicating the server is waiting for connections:
Waiting for connection request
The server is interactive and reads the command from stdin on startup.

Running the Client

Open another terminal and make requests using the client:
1

Build the Client

cd Client
mvn clean package
2

Start the Interactive Client

Run the client program:
java -cp target/classes client.CLient
The client will prompt you for commands interactively.
3

Make a GET Request

When prompted “Enter your command..”, type:
httpc get -v http://localhost:8080/
This retrieves a directory listing from the server. When asked if you want to continue, type yes.
4

Make a POST Request

At the next command prompt, upload content:
httpc post -v -d "Hello, Selective Repeat UDP!" http://localhost:8080/test.txt
Type yes to continue.
5

Retrieve the Uploaded File

At the next prompt, retrieve the file you just created:
httpc get -v http://localhost:8080/test.txt
You should see the content you uploaded. Type no to exit the client.
The client runs in an interactive loop, prompting for commands until you type “no” when asked to continue.

Understanding the Protocol Flow

When you run a request, here’s what happens under the hood:
1

Connection Establishment

The client initiates a three-way handshake:
// Client sends SYN (type=2)
Packet syn = new Packet.Builder()
    .setType(2)
    .setSequenceNumber(1L)
    .setPortNumber(serverAddr.getPort())
    .setPeerAddress(serverAddr.getAddress())
    .setPayload("1".getBytes())
    .create();
Server responds with SYN-ACK, client sends ACK to complete the handshake.
2

Data Transmission

The client chunks the HTTP request into 1013-byte packets:
final int sizeMB = 1013;
List<byte[]> chunks = IntStream.iterate(0, i -> i + sizeMB)
    .limit((datab.length + sizeMB - 1) / sizeMB)
    .mapToObj(i -> Arrays.copyOfRange(datab, i, Math.min(i + sizeMB, datab.length)))
    .collect(Collectors.toList());
3

Windowed Transmission

The client sends up to 100 packets (the window size) without waiting for ACKs:
int tobesent = Math.min(nofpackets, window);
for (int i = 2; i <= tobesent + 1; i++) {
    socket.send(packets.get(i - 2));
    Thread t = new Thread(new Timer(i, socket, 0));
    t.start();
}
4

Selective Acknowledgment

The server sends ACKs for received packets and NACKs for missing ones:
  • ACK (type=1): Acknowledges receipt of a packet
  • NACK (type=4): Requests retransmission of a missing packet
5

Response Reception

The server sends the HTTP response using the same reliable protocol, and the client reassembles the packets in order.

Command Reference

Client Commands

Syntax:
httpc get [-v] [-h key:value] URL
Options:
  • -v - Verbose mode (prints headers)
  • -h key:value - Add HTTP headers
  • -o filename - Save output to file
Example:
httpc get -v -h "User-Agent:MyClient" http://localhost:8080/file.txt
Syntax:
httpc post [-v] [-h key:value] [-d data] [-f file] URL
Options:
  • -v - Verbose mode
  • -h key:value - Add HTTP headers
  • -d data - Inline data
  • -f filename - Read data from file
  • -o filename - Save output to file
Example:
httpc post -v -f input.txt http://localhost:8080/output.txt

Router Commands

router --port=3000 --drop-rate=0.0 --max-delay=0 --seed=1
Options:
  • --port - Port number (default: 3000)
  • --drop-rate - Packet drop probability 0.0-1.0 (default: 0.0)
  • --max-delay - Maximum packet delay (default: 0)
  • --seed - Random seed for reproducible tests

Testing Different Network Conditions

Try these router configurations to test the protocol under different conditions:
./router --port=3000 --drop-rate=0.0 --max-delay=0
Use the --seed parameter for reproducible testing. The same seed will produce the same pattern of packet drops and delays.

Troubleshooting

  • Ensure the router is running on port 3000
  • Check that the server is running and listening on the specified port
  • Verify firewall settings allow UDP traffic
  • Check the router’s drop rate (lower it for testing)
  • Increase the timeout value in the protocol
  • Look at router logs for packet forwarding information
  • Ensure you’re using Java 11 or later
  • Run mvn clean install to fetch all dependencies
  • Check that JAVA_HOME is set correctly

Next Steps

Architecture Overview

Learn how the three components work together

Client Usage Guide

Explore all client features and commands

Server Setup

Configure and customize the server

API Reference

Dive into the protocol implementation details

Build docs developers (and LLMs) love