A minimal HTTP server written from scratch in C. Binds to localhost:3000 and responds to requests with a plain HTML page β no libraries, no frameworks, just raw sockets and the C standard library.
http-server/
βββ Server.h # Server struct definition and function declarations
βββ Server.c # Socket setup, bind, listen, accept, and HTTP response logic
βββ test.c # Entry point β initialises and runs the server
- GCC or any C99-compatible compiler
- Linux / macOS (uses POSIX sockets)
gcc test.c Server.c -o server./serverThen open your browser and navigate to:
http://localhost:3000
You should see:
Hello, World!
- Socket creation β opens a TCP socket with
socket() - Bind β binds to
127.0.0.1:3000withbind() - Listen β marks the socket as passive with
listen() - Accept loop β blocks on
accept(), handling one connection at a time - HTTP response β writes a minimal valid HTTP/1.1 response with a
Content-Type: text/htmlheader and an<h1>Hello, World!</h1>body - Close β closes the connection socket and loops back to accept the next request