A lightweight, high-throughput Web Server built from scratch in C++17 using the Windows Sockets API (Winsock2).
Unlike typical web frameworks, this project implements the core networking layer manually to handle raw TCP connections, HTTP parsing, and concurrent client management using a custom Thread Pool.
- Custom Thread Pool: Implemented a pre-allocated pool of worker threads to handle concurrent connections efficiently, avoiding the overhead of creating and destroying threads per request.
- Raw Socket Programming: Built directly on
winsock2without external networking libraries (like Boost.Asio) to demonstrate low-level systems knowledge. - Thread Safety: Utilizes
std::mutex,std::unique_lock, andstd::condition_variableto manage the task queue safely across multiple threads. - Modern Build System: Fully integrated with CMake for cross-platform build management.
- HTTP Protocol: Supports
GETrequests, serves static files (HTML, CSS, Images), and handles 404/500 errors.
[Client] -> [Load Balancer / Socket Listener]
|
[Job Queue (Thread Safe)]
|
-----------------------------
| | |
[Worker Thread] [Worker Thread] [Worker Thread]
| | |
[Parse HTTP] [Read File] [Send Response]
- C++ Compiler: MSVC (Visual Studio), G++, or Clang.
- CMake: Version 3.10 or higher.
- Operating System: Windows (Required for
winsock2).
Clone the Repository
git clone [https://github.com/chetan-code/HTTPServer.git](https://github.com/chetan-code/HTTPServer.git) cd HTTPServerCreate a Build Directory It is best practice to keep build files separate from source code.
mkdir build cd buildGenerate Build Files Run CMake to verify your compiler and generate the Makefiles or Visual Studio solution.
cmake ..
Compile the Project This command compiles the source code and links the
ws2_32library.cmake --build .
Important: The server looks for the www folder in its current working directory. You must run the executable from the project root, not from inside the build folder.
Navigate back to the project root:
cd ..Run the executable:
.\build\Debug\server.exe
Verify: Open your browser and navigate to:
http://localhost:8080