This is a minimal HTTP server built in C++ using Winsock2.
It supports both GET and POST requests, and logs the client request to the console.
- HTTP protocol is system-independent.
- What differs is how the OS exposes sockets:
- Unix/Linux/macOS → use POSIX sockets (file descriptors:
intvalues). - Windows → use Winsock, which returns a
SOCKETtype.
- Unix/Linux/macOS → use POSIX sockets (file descriptors:
This server:
- Initializes Winsock (
WSAStartup). - Creates a TCP socket (
socket(AF_INET, SOCK_STREAM, 0)). - Binds it to
PORT 8080(or any port you set). - Listens for connections (
listen). - Accepts clients (
accept). - Reads the request (
recv). - Responds with:
- GET → returns
"heyo!". - POST → echoes the POST body back in the response.
- GET → returns
- Windows (tested on MSYS2 / MinGW).
- Compiler supporting C++11 or higher.
g++ server.cpp -o server.exe -lws2_32