Learn real network programming in < 500 lines of actual server code.
A deliberately tiny, dependency-free HTTP/1.0 server written in standard C.
Great for students, embedded projects, or anyone who wants to understand how web servers actually work under the hood.
Most "learn HTTP servers" tutorials use Python or Go.
Those are great — but they hide the raw socket mechanics, threading choices, buffering issues, and protocol edge cases.
C-Web forces you to see them.
Compared to Python's http.server:
- ~20–50× faster static file serving (no interpreter overhead)
- No runtime needed — just compile and run
- You actually understand the bytes on the wire
- Serves static files (HTML, CSS, JS, images, etc.) from a
public/folder - Proper (but minimal) HTTP/1.0 request parsing & response generation
- Clean shutdown on Ctrl+C
- Heavily commented code — every non-obvious line is explained
- Single-threaded, blocking accept loop (easy to extend to threads/select/poll later)
Intentionally missing (on purpose):
- HTTP/1.1 keep-alive & pipelining
- HTTPS
- Dynamic routes / CGI / templates
- Large file sendfile() optimization
- Config file / CLI arguments
All of those are excellent follow-up exercises.
git clone https://github.com/yourusername/c-web.git
cd c-web
make run
# or
make
./bin/serverThen open:
http://localhost:9999/
Default port is 9999 (change in server.c if you want).
c-web/
├── src/
│ ├── server.c # main() + launch loop
│ └── http.c # request parsing + response building
├── include/
│ └── http.h
├── public/ # put your static files here
│ ├── index.html
│ ├── style.css
│ └── img/
├── bin/ # compiled binary (gitignored)
├── Makefile
└── README.md
Start here:
src/server.c→ socket(), bind(), listen(), accept() loopsrc/http.c→ reading & very basic parsing of HTTP request line + headers- Response path → how Content-Type is guessed, how file is sent in chunks
Good first extensions:
- Add simple route handling (
/api/*→ JSON,/→ index.html) - Implement directory listing
- Add very basic logging (IP + path + status)
- Switch to non-blocking I/O + select()
- Support HTTP/1.1 Connection: keep-alive
docs/LEARNING_C.md— C concepts explained with Python / JavaScript analogiesdocs/ARCHITECTURE.md— Diagrams of socket flow, request lifecycle, memory handling
- Simplicity > features
- Clarity > cleverness
- Education > performance tricks
If the core logic exceeds ~500 lines, something probably went wrong.
MIT - do whatever you want.
Would appreciate a link back if you use it in a blog post or tutorial.
Inspired by classic tiny servers (Tinyhttpd, many YouTube socket tutorials) but rewritten from scratch to be clearer and more modern-C friendly.
Happy hacking — and enjoy seeing your browser talk directly to your own tiny server!