Skip to content

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

HTTP Server in C

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.


πŸ“ Project Structure

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

Prerequisites

  • GCC or any C99-compatible compiler
  • Linux / macOS (uses POSIX sockets)

Build

gcc test.c Server.c -o server

Run

./server

Then open your browser and navigate to:

http://localhost:3000

You should see:

Hello, World!

πŸ”§ How It Works

  1. Socket creation β€” opens a TCP socket with socket()
  2. Bind β€” binds to 127.0.0.1:3000 with bind()
  3. Listen β€” marks the socket as passive with listen()
  4. Accept loop β€” blocks on accept(), handling one connection at a time
  5. HTTP response β€” writes a minimal valid HTTP/1.1 response with a Content-Type: text/html header and an <h1>Hello, World!</h1> body
  6. Close β€” closes the connection socket and loops back to accept the next request

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages