A simple web server implemented in C++ that handles HTTP requests and serves static files.
- TCP socket communication using Winsock2
- HTTP/1.1 protocol support
- GET request handling
- Static file serving (HTML, JPG, TXT)
- 404 error handling
- Proper connection management
.
├── webserver.cpp # Main server implementation
├── index.html # Default landing page
├── duck/ # Directory containing duck images
│ └── duck selfie.jpg
└── plant/ # Directory containing plant-related files
├── my_plant.jpg
└── word.txt
/- Main landing page with server information/duck- Duck selfie page/plant/my_plant.jpg- Plant image/plant/word.txt- Text file
The server is built using:
- Windows Socket API (Winsock2)
- Standard C++ libraries
- Initializes Winsock2 for network communication
- Creates a TCP socket and binds it to port 8080
- Listens for incoming connections
- Accepts client connections
- Processes HTTP requests
- Serves requested files
- Closes connections properly
- Compile the server:
make main- Run the server:
.\webserver.exe- Access the server using your browser (default port is 8080):
http://localhost:8080
- Windows operating system
- C++ compiler (g++ or compatible)
- Winsock2 library