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
Enter Server Command
When prompted, enter the server command:You’ll see:
Waiting for connection requestServer Command Syntax
The httpfs server accepts the following command format:Enables verbose logging to show detailed information about connections, requests, and responses.
Specifies the port number on which the server listens for incoming connections.
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):This starts the server on port 8080 serving files from the current directory without verbose logging.
Custom Port
Specify a different port:Custom Directory
Serve files from a specific directory:Verbose Mode
Enable detailed logging for debugging:Complete Configuration
Combine all options:Server Behavior
Connection Handling
The server uses a multi-threaded architecture to handle multiple clients: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
Request Processing
The server handles HTTP requests through the Selective Repeat protocol:- Receive Packets
- Process Request
- Generate Response
- Complete
- 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: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:HttpcLib.getResponse() method processes the request.
POST Requests
POST requests can create or update files:HttpcLib.postResponse() method handles the data.
Logging and Monitoring
Verbose Output
When verbose mode is enabled (-v), the server logs detailed information:
Without Verbose Mode
Without the-v flag, the server runs quietly and only logs minimal information:
Configuration Examples
- Development
- Testing
- Production
- Custom Port
For local development with detailed logging:
Use verbose mode to see all connection and packet details.
Complete Setup Example
Here’s how to set up a complete working environment:Troubleshooting
Port already in use
Port already in use
If you see a bind error, the port is already in use:
Connection timeout
Connection timeout
Ensure the router is running before starting the server:
Directory not accessible
Directory not accessible
Make sure the specified directory exists and has proper permissions:
Packets not acknowledged
Packets not acknowledged
Check router logs for dropped packets:If too many packets are dropped, reduce the drop rate:
Handler errors
Handler errors
Enable verbose mode to see detailed handler logs: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