A multi-threaded HTTP/1.1 compliant web server implementation in C++ using Windows Sockets API (Winsock). This server supports multiple simultaneous connections, multi-language content delivery, and full CRUD operations.
Ori Braverman
- Features
- Architecture
- Prerequisites
- Installation
- Configuration
- Usage
- Supported HTTP Methods
- Multi-Language Support
- API Examples
- File Structure
- Technical Details
- Troubleshooting
- Contributing
- HTTP/1.1 Compliance: Full support for HTTP/1.1 protocol
- Multi-threaded: Handles up to 60 simultaneous connections
- Multi-language Content: Serves content in English, French, and Hebrew
- Complete CRUD Operations: GET, POST, PUT, DELETE support
- Static File Serving: Serves HTML files and other static content
- Connection Management: Automatic timeout and cleanup of inactive connections
- Error Handling: Proper HTTP status codes and error responses
- Query String Support: Language selection via URL parameters
The server follows a modular architecture with clear separation of concerns:
┌─────────────────────────────────────┐
│ Client Requests │
└─────────────┬───────────────────────┘
│
┌─────────────▼───────────────────────┐
│ Main Server Loop │
│ (server3.cpp) │
│ - Socket Management │
│ - Connection Handling │
│ - Request/Response Coordination │
└─────────────┬───────────────────────┘
│
┌─────────────▼───────────────────────┐
│ Server Utilities │
│ (ServerUtilities.cpp/.h) │
│ - HTTP Method Processing │
│ - File Operations │
│ - Response Generation │
│ - Language Detection │
└─────────────┬───────────────────────┘
│
┌─────────────▼───────────────────────┐
│ Static Content │
│ (HTML_FILES/) │
│ - Multi-language HTML files │
│ - Error pages │
│ - Test content │
└─────────────────────────────────────┘
- Operating System: Windows (uses Windows Sockets API)
- Compiler: Microsoft Visual Studio 2019 or later (v142 toolset)
- SDK: Windows 10 SDK
- Network: Available port 27015
git clone https://github.com/OriBraverman/HTTP-Web-Server.git
cd HTTP-Web-ServerExtract the HTML_FILES.rar archive to C:\Temp\:
C:\Temp\HTML_FILES\
├── English\
│ └── index.html
├── French\
│ └── index.html
├── Hebrew\
│ └── index.html
├── Error\
│ └── error.html
├── fileToAdd.txt
└── fileToDelete.txt
- Open
Server3\Server3.slnin Visual Studio - Select your preferred configuration (Debug/Release)
- Build the solution (Ctrl+Shift+B)
The server configuration is defined in ServerUtilities.h:
- Port: 27015 (HTTP_PORT constant)
- Max Connections: 60 (MAX_SOCKETS constant)
- Buffer Size: 2048 bytes (BUFFER_SIZE constant)
- Connection Timeout: 120 seconds
The server expects content to be organized as follows:
C:\Temp\HTML_FILES\
├── English\ # English content
├── French\ # French content
├── Hebrew\ # Hebrew content
└── Error\ # Error pages
- Run the compiled executable from Visual Studio or command line
- The server will start and display:
Waiting for client to connect to the server. - The server is now ready to accept connections on
http://localhost:27015
- Access English content:
http://localhost:27015/index.html - Access French content:
http://localhost:27015/index.html?lang=fr - Access Hebrew content:
http://localhost:27015/index.html?lang=he
Retrieves static content from the server.
GET /index.html HTTP/1.1
Host: localhost:27015- Response: Returns the requested file content
- Status Codes: 200 (OK), 404 (Not Found)
Sends data to the server for processing.
POST /endpoint HTTP/1.1
Host: localhost:27015
Content-Length: 13
Hello, Server!- Response: Echoes received data to console
- Status Code: 200 (OK)
Creates or updates files on the server.
PUT /newfile.txt HTTP/1.1
Host: localhost:27015
Content-Length: 20
This is new content!- Status Codes:
- 200 (OK) - File updated
- 201 (Created) - New file created
- 204 (No Content) - Empty content
- 412 (Precondition Failed) - Error
Removes files from the server.
DELETE /fileToDelete.txt HTTP/1.1
Host: localhost:27015- Status Codes:
- 200 (OK) - File deleted successfully
- 204 (No Content) - File not found or delete failed
Returns headers only (no body content).
HEAD /index.html HTTP/1.1
Host: localhost:27015- Response: Headers with content information
- Status Codes: 200 (OK), 404 (Not Found)
Returns supported HTTP methods.
OPTIONS / HTTP/1.1
Host: localhost:27015- Response:
Allow: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE - Status Code: 204 (No Content)
Echoes the received request back to the client.
TRACE / HTTP/1.1
Host: localhost:27015- Response: Original request message
- Status Code: 200 (OK)
The server supports content in multiple languages through query string parameters:
| Language | Query Parameter | Example |
|---|---|---|
| English (default) | lang=en or no parameter |
index.html |
| French | lang=fr |
index.html?lang=fr |
| Hebrew | lang=he |
index.html?lang=he |
The server supports various language code variants:
- English:
en,en-US,en-GB,en-AU,en-CA, etc. - French:
fr,fr-FR,fr-CA,fr-CH,fr-BE, etc. - Hebrew:
he,he-IL
- English: Britain's National Dishes
- French: French cuisine and culture
- Hebrew: Israeli content with RTL support
curl http://localhost:27015/index.htmlcurl -X POST -d "Hello from client!" http://localhost:27015/curl -X PUT -d "New file content" http://localhost:27015/newfile.txtcurl -X DELETE http://localhost:27015/fileToDelete.txtcurl http://localhost:27015/index.html?lang=fr# GET request
Invoke-WebRequest -Uri "http://localhost:27015/index.html"
# POST request
Invoke-WebRequest -Uri "http://localhost:27015/" -Method POST -Body "Hello Server"
# PUT request
Invoke-WebRequest -Uri "http://localhost:27015/test.txt" -Method PUT -Body "Test content"HTTP-Web-Server/
├── README.md # This documentation
├── README.txt # Original brief documentation
├── HTML_FILES.rar # Static content archive
└── Server3/ # Main server implementation
├── Server3.sln # Visual Studio solution
├── Server3.vcxproj # Project file
├── server3.cpp # Main server logic
├── ServerUtilities.h # Server utilities header
└── ServerUtilities.cpp # Server utilities implementation
- Main entry point and server loop
- Socket initialization and management
- Connection acceptance and handling
- Select-based I/O multiplexing
- Data structures and enums
- Function declarations
- Configuration constants
- HTTP method implementations
- File operations (read, write, delete)
- Response generation
- Language detection logic
- Connection management utilities
- Uses Winsock2 API for Windows networking
- Non-blocking sockets with select() for multiplexing
- Maximum 60 concurrent connections
- Automatic cleanup of inactive connections (2-minute timeout)
- HTTP/1.1 compliant responses
- Proper status codes and headers
- Content-Type detection
- Content-Length calculation
- Date headers with current timestamp
- Fixed-size buffers (2048 bytes)
- Proper buffer cleanup after each request
- Memory reuse for connection structures
- Comprehensive error checking for all socket operations
- Graceful handling of client disconnections
- Proper resource cleanup on errors
- HTTP error responses for invalid requests
Error at bind(): 10048
Solution: Ensure port 27015 is not being used by another application.
404 Not Found
Solution: Verify HTML_FILES is extracted to C:\Temp\HTML_FILES\
Solution: Check if the client request is complete and properly formatted.
Solution:
- Ensure Windows 10 SDK is installed
- Verify Visual Studio version compatibility
- Check that Ws2_32.lib is properly linked
The server provides verbose console output including:
- Connection establishment/termination
- Request details
- Response information
- Error messages
- Maximum 60 simultaneous connections
- 2-minute connection timeout
- 2048-byte buffer limitation
- Synchronous file I/O operations
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow existing code style and patterns
- Add appropriate error handling
- Update documentation for new features
- Test with multiple browsers and HTTP clients
This project is part of an educational implementation. Please respect the original author's work and provide appropriate attribution when using or modifying this code.
For questions or support, please refer to the project repository or contact the author.