This project is a basic multithreaded TCP server written in C using the Winsock library. The server listens for incoming connections on port 8080 and sends a simple HTTP response. It demonstrates socket programming, multithreading, and basic HTTP handling in Windows.
✅ Socket Initialization: Uses Winsock (WSAStartup()) to create a TCP socket.
✅ Binding & Listening: Binds to localhost:8080 and listens for incoming connections.
✅ Multithreading: Uses CreateThread() to handle multiple clients concurrently.
✅ Basic HTTP Handling: Sends a simple Hello, world! response.
✅ Graceful Cleanup: Uses closesocket() and WSACleanup().
- Windows OS
- MinGW or MSVC (for compiling C code)
- Git (optional, for version control)
-
Clone the Repository
git clone <your-repo-url> cd <your-repo-folder>
-
Compile the Code
- Using MinGW:
gcc src/server.c -o bin/server.exe -lws2_32
- Using MSVC:
cl src/server.c /link ws2_32.lib
- Using MinGW:
-
Run the Server
bin/server.exe
-
Test the Server
- Open a browser and visit:
http://127.0.0.1:8080 - Or use cURL in a terminal:
curl -v http://localhost:8080
- You should see:
Hello, world!
- Open a browser and visit:
- Initialize Winsock (
WSAStartup()) - Create a TCP socket (
socket(AF_INET, SOCK_STREAM, 0)) - Configure socket options (
setsockopt()) - Bind the socket (
bind()) tolocalhost:8080 - Listen for incoming connections (
listen()) - Accept client connections (
accept()) - Create a new thread for each client using
CreateThread() - Handle the client request (introduce a delay to test multithreading)
- Send a response (
send()) and close the connection - Cleanup (
closesocket(),WSACleanup())
To verify multithreading, send multiple requests in quick succession:
curl -v http://localhost:8080 &
curl -v http://localhost:8080 &If working correctly, multiple requests will be processed simultaneously.
🔹 Improve HTTP Parsing: Extract method, headers, and request body.
🔹 Serve Static Files: Handle .html, .css, .js, and images.
🔹 Support HTTP Methods: Implement GET (serve files) and POST (read body).
🔹 Thread Pool & Demultiplexing: Optimize performance for concurrent requests.
If you’d like to contribute:
- ** check out the project roadmap on my notion page https://www.notion.so/HTTP-Server-Project-19d9ebfa16f8809eb893c548ff83956c?pvs=4 or simple read roadmap.md**
- Fork the repo
- Create a new branch
- Submit a pull request