Skip to main content
The httpfs server is a simple HTTP file server that serves files from a directory using the Selective Repeat UDP protocol for reliable data transfer.

Quick Start

1

Start the Router

The router must be running before starting the server:
./router --port 3000
2

Launch the Server

cd Server
mvn exec:java -Dexec.mainClass="Server.ServerCommand"
3

Enter Server Command

When prompted, enter the server command:
httpfs -v -p 8080 -d /path/to/files
You’ll see: Waiting for connection request
4

Test the Server

In another terminal, use the httpc client to test:
httpc get http://localhost:8080/get

Server Command Syntax

The httpfs server accepts the following command format:
httpfs [options]
-v, --verbose
flag
Enables verbose logging to show detailed information about connections, requests, and responses.
-p, --port
integer
default:"8080"
Specifies the port number on which the server listens for incoming connections.
-d, --directory
string
default:"."
Sets the root directory from which files are served. Defaults to the current directory.

Basic Configuration

Default Configuration

Run the server with default settings (port 8080, current directory):
httpfs
This starts the server on port 8080 serving files from the current directory without verbose logging.

Custom Port

Specify a different port:
httpfs -p 3000

Custom Directory

Serve files from a specific directory:
httpfs -d /var/www/files

Verbose Mode

Enable detailed logging for debugging:
httpfs -v

Complete Configuration

Combine all options:
httpfs -v -p 8080 -d /home/user/public

Server Behavior

Connection Handling

The server uses a multi-threaded architecture to handle multiple clients:
1

Wait for Connection

The server listens on the specified port for SYN packets:
Waiting for connection request
2

Three-Way Handshake

When a client connects, the server performs a three-way handshake:
  • Receives SYN from client
  • Sends SYN-ACK to client
  • Waits for ACK from client
3

Create Client Handler

A dedicated handler thread is created for each unique client:
Client handler created for client with address /192.168.1.100
4

Process Requests

The handler receives and processes requests from the client.

Request Processing

The server handles HTTP requests through the Selective Repeat protocol:
handler /192.168.1.100: waiting for packets from client /192.168.1.100
handler /192.168.1.100: waiting for the request
The server receives data packets and sends acknowledgments using:
  • ACK packets: For successfully received in-order packets
  • NACK packets: For missing packets (triggers retransmission)

Selective Repeat Protocol

The server implements Selective Repeat with the following parameters:
// Maximum number of unacknowledged packets
private static int windowRec = 100;
The window size of 100 packets allows the server to send up to 100 KB of data before requiring acknowledgments.

File Operations

GET Requests

The server handles GET requests to retrieve files or directory listings:
# From client
httpc get http://localhost:8080/get?file=test.txt
The server’s HttpcLib.getResponse() method processes the request.

POST Requests

POST requests can create or update files:
# From client
httpc post -d 'file content' http://localhost:8080/post
The server’s HttpcLib.postResponse() method handles the data.

Logging and Monitoring

Verbose Output

When verbose mode is enabled (-v), the server logs detailed information:
Waiting for connection request
Client handler created for client with address /192.168.1.100
Enable verbose mode during development and debugging to understand the server’s behavior.

Without Verbose Mode

Without the -v flag, the server runs quietly and only logs minimal information:
Handler /192.168.1.100: request received
Handler /192.168.1.100: Response Sent

Configuration Examples

For local development with detailed logging:
httpfs -v -p 8080 -d ./public
Use verbose mode to see all connection and packet details.

Complete Setup Example

Here’s how to set up a complete working environment:
1

Terminal 1: Start Router

cd Router
./router --port 3000 --drop-rate 0.1 --max-delay 50ms
Output:
config: drop-rate=0.10, max-delay=50ms, seed=1234567890
router is listening at :3000
2

Terminal 2: Start Server

cd Server
mvn exec:java -Dexec.mainClass="Server.ServerCommand"
Enter command:
httpfs -v -p 8080 -d ./files
Output:
Waiting for connection request
3

Terminal 3: Test with Client

cd Client
mvn exec:java -Dexec.mainClass="client.CLient"
Enter command:
httpc get -v http://localhost:8080/get
4

Monitor Logs

In the server terminal, you’ll see:
Client handler created for client with address /127.0.0.1
handler /127.0.0.1: waiting for packets from client /127.0.0.1
handler /127.0.0.1: Received all request packets
Handler /127.0.0.1: request received
Handler /127.0.0.1: Response Created
Handler /127.0.0.1: Sending the Response
Handler /127.0.0.1: Response Sent

Troubleshooting

If you see a bind error, the port is already in use:
# Check what's using the port
lsof -i :8080

# Use a different port
httpfs -p 8081
Ensure the router is running before starting the server:
# Start router first
./router --port 3000

# Then start server
httpfs -v -p 8080
Make sure the specified directory exists and has proper permissions:
# Create directory if needed
mkdir -p /path/to/files

# Check permissions
ls -la /path/to/files

# Set permissions if needed
chmod 755 /path/to/files
Check router logs for dropped packets:
# Router logs are in router.log
tail -f router.log
If too many packets are dropped, reduce the drop rate:
./router --port 3000 --drop-rate 0.05
Enable verbose mode to see detailed handler logs:
httpfs -v -p 8080
Look for error messages in the handler output.

Performance Considerations

Window Size

The default window size is 100 packets (approximately 100 KB). Larger windows allow faster transfers but require more memory.

Timeout Values

Socket timeout is set to 30ms for acknowledgments. Adjust based on network conditions.

Retransmission

Maximum of 10 retries per packet before giving up. This prevents infinite retransmission loops.

Packet Size

Each packet carries up to 1013 bytes of payload. This is optimized for UDP transmission.

Next Steps

Client Usage

Learn how to make requests to the server

Router Configuration

Configure network conditions for testing

Build docs developers (and LLMs) love