This project implements a small web server in C++ that supports multiple concurrent connections without using multi-threading or blocking sockets. The server is designed to handle various HTTP methods.
- HTTP Methods Supported: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE
- Language Support for GET Requests:
- Query string parameter
lang
can be used to request the page in different languages:lang=he
for Hebrewlang=en
for Englishlang=fr
for French
- Query string parameter
- POST Requests: The server logs the received strings to the console.
- Non-Blocking Sockets: Handles multiple connections concurrently using non-blocking sockets.
- Timeout Management: Closes connections if the request is idle for more than two minutes.
- Content-Type: Supports text/html responses.
Make sure to add test files:
Add the contents of the /pages directory to the folder C:\temp.
-
Start the server:
./server
-
Access the server:
- Using a web browser: http://localhost:8080
- Using an HTTP client (e.g., curl, Postman)
-
Test different HTTP methods:
- GET request (specifying language):
curl -X GET "http://localhost:8080/?lang=en"
- POST request:
curl -X POST -d "data=example" http://localhost:8080
- GET request (specifying language):
The server is implemented using non-blocking sockets and the select
system call to manage multiple concurrent connections. It supports essential HTTP methods and language-based responses for GET requests.
When a GET request is received, the server checks for the lang
query parameter and returns the appropriate language version of the page if available. If no language is specified or the requested language is not supported, the server defaults to English.
POST requests are expected to contain strings which the server logs to the console for demonstration purposes.
- Wireshark: For capturing and analyzing network traffic.
- cURL: For sending various HTTP requests to the server.
- Use Wireshark to capture HTTP traffic to and from the server.
- Send different types of HTTP requests (OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE) and verify the responses.
- Check the server console for POST request data logging.
- Validate that connections are properly closed after being idle for more than two minutes.