Ronenii / HTTP-TCP-Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non-Blocking Web Server in C++

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.

Features

  • 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 Hebrew
      • lang=en for English
      • lang=fr for French
  • 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.

Note

Make sure to add test files:

Add the contents of the /pages directory to the folder C:\temp.

Usage

  1. Start the server:

    ./server
  2. Access the server:

  3. 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

Development

Server Implementation

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.

Handling 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.

Handling POST Requests

POST requests are expected to contain strings which the server logs to the console for demonstration purposes.

Testing

Tools Used

  • Wireshark: For capturing and analyzing network traffic.
  • cURL: For sending various HTTP requests to the server.

Test Procedure

  1. Use Wireshark to capture HTTP traffic to and from the server.
  2. Send different types of HTTP requests (OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE) and verify the responses.
  3. Check the server console for POST request data logging.
  4. Validate that connections are properly closed after being idle for more than two minutes.

About


Languages

Language:C++ 97.1%Language:HTML 2.9%