A minimal HTTP/1.1 server implemented entirely from scratch in C++ using raw TCP sockets via Windows Winsock.
This project intentionally avoids frameworks and third-party libraries to focus on core networking fundamentals and protocol behavior.
This project exists to deeply understand how an HTTP server actually works at the socket level on Windows.
Rather than abstracting networking behind libraries, it demonstrates:
- How TCP connections are established and terminated
- How HTTP is transmitted over raw byte streams
- How browsers behave when protocol expectations are not met
- How to correctly handle edge cases that are often hidden by frameworks
The goal is learning and correctness, not feature completeness or production readiness.
- Initializes the Windows Winsock subsystem
- Creates an IPv4 TCP socket
- Binds to port
8080 - Listens for incoming connections
- Accepts a client connection
- Reads raw TCP data using
recv()in a loop - Detects HTTP request boundaries using
\r\n\r\n - Correctly handles all
recv()return values:> 0— data received== 0— graceful client disconnect< 0— socket error
- Parses the request path
- Sends valid HTTP/1.1 responses:
200 OKfor/with HTML content404 Not Foundfor all other paths
- Gracefully shuts down the connection using
shutdown()to ensure browsers do not hang
The server follows the classic blocking TCP socket lifecycle on Windows:
- Windows Winsock API usage
- TCP connection establishment and teardown
- Blocking socket behavior
- Partial TCP reads and stream reassembly
- HTTP request boundary detection
- Minimal HTTP/1.1 response formatting
- Proper use of
shutdown()vsclosesocket() - Real browser interoperability considerations
This project explicitly handles common real-world failure modes:
- Winsock initialization failure
- Socket creation failure
- Bind failure (e.g., port already in use)
- Accept failure
- Partial TCP reads across multiple
recv()calls - Graceful client disconnect (
recv() == 0) - Socket errors (
recv() < 0) - Browser hanging due to missing TCP FIN (explicitly fixed using
shutdown())
- Build the project using a Windows C++ compiler (Visual Studio or equivalent).
- Ensure no other service is using port
8080. - Run the executable.
- The server will block and wait for an incoming connection.
Navigate to:
/returns200 OKwith HTML content- Any other path returns
404 Not Found
curl -v http://localhost:8080/
Non-existent path:
curl -v http://localhost:8080/does-not-exist
- Single-connection, blocking design
- No concurrency or threading
- No HTTP header parsing beyond the minimum required
- No request body handling
- No HTTPS / TLS
- No production performance optimizations
These limitations are intentional to preserve clarity and focus on fundamentals.
- Multi-client support (threads or
select()) - Robust HTTP header parsing
- Additional HTTP methods
- Keep-alive connections
- Logging and metrics
- IPv6 support
Understanding this project demonstrates practical knowledge of:
- TCP socket programming on Windows
- HTTP over raw TCP
- Correct connection termination semantics
- Browser behavior and protocol expectations
- What higher-level web frameworks abstract away
This is a foundational systems and networking exercise, not a production server.