A basic HTTP server implemented in C++ using Winsock2. This server listens for incoming connections on port 8080 and serves a simple HTML response to each client.
- Simple HTTP Response : Returns a basic HTML page with a welcome message.
- TCP Connection Handling : Uses Winsock to accept client connections over TCP.
- Multi-Client Support : Handles one client at a time (single-threaded)
Make sure you have a C++ compiler that supports Winsock2. For Windows, Microsoft Visual Studio is recommended.
- Clone the repository :
git clone https://github.com/XanderSteyn/HTTP-Server.git
cd HTTP-Server
- Compile the C++ code with your preferred C++ compiler. Example using g++ :
g++ -o HTTPServer HTTPServer.cpp -lws2_32
- Run the compiled program :
./SimpleHTTPServer.exe
After starting the server, you can test it by navigating to http://localhost:8080 in your browser. You should see the following message :
<h1>This is a Simple HTTP Response</h1>
- Socket Initialization : The server initializes Winsock and creates a TCP socket.
- Bind & Listen : The server binds the socket to port 8080 and listens for incoming connections.
- Handle Client Requests : When a client connects, it receives an HTTP request, which is then processed.
- Send Response : A simple HTML response is sent back to the client.
- Close Connection : After sending the response, the server closes the client connection and waits for the next one.
- This is a single-threaded server and can handle one client at a time.
- The server listens on port 8080. Make sure the port is not in use by another application.
- Only works on Windows due to reliance on the Winsock library.