An HTTP protocol-based web server written in C for CSOC'25.
{
"Name": "Jayesh Krishan Puri",
"Roll no.": 24155058,
"Branch": "B.Tech Mining Engineering"
}
- Introduction
- Features
- Project Structure
- How to Build and Run
- How the Code Works (Beginner Level)
- Cleaning Build Files
- License
This project is a minimalist web server built using the C programming language. It listens on your computer’s localhost
and serves files over HTTP — the protocol that powers the web. This server is designed to help you understand the fundamentals of:
- TCP sockets
- HTTP request handling
- Static file serving
- Logging mechanisms
It's a great entry point into low-level networking and systems programming!
- 📡 Handles HTTP requests on port 3003
- 📂 Serves static files from the
public/
directory - 📄 Logs all incoming requests and errors
- ⚙️ Clean and build using a Makefile
.
├── webserver # Compiled binary
├── src/ # Source code files
│ ├── main.c # Main server logic
│ ├── content_headers.c/h # Sets MIME types for files
│ ├── error_logging.c/h # Error handling and logging
│ ├── request_logging.c/h # Request access logging
│ └── headers.h # HTTP and server config
├── public/ # Static HTML/CSS/JS/assets to serve
├── logs/ # Log output directory
│ └── server_activity.log
├── Makefile # Build and clean instructions
├── README.md # Project documentation
└── LICENSE # License file
git clone https://github.com/Jayesh-Dev21/C-webserver.git
cd C-webserver
make
./webserver
Open your browser and go to:
http://localhost:3003/
You should see the default web page (served from public/index.html
) or any other static files you’ve added.
- The server setup and logic is inside
src/main.c
. - It uses a socket to listen for HTTP requests from browsers.
- When a request comes in:
- It reads the path and determines which file to serve.
- It fetches the correct MIME type using
content_headers.c
. - If the file exists, it serves it with the right HTTP headers.
- If there’s an issue (e.g., file not found), it logs the error and returns an error page.
- Logs for all requests and errors are stored in the
logs/
directory.
File | Description |
---|---|
main.c |
Starts the server and handles connections |
content_headers.c/h |
Assigns MIME types to files |
error_logging.c/h |
Logs runtime and file errors |
request_logging.c/h |
Logs all HTTP requests with metadata |
headers.h |
Common declarations and configurations |
Makefile |
Handles build and clean operations |
🔰 New to C or web servers? Read the files in this order for best understanding:
main.c
content_headers.c/h
request_logging.c/h
error_logging.c/h
headers.h
To remove compiled files and logs:
make clean
This project is licensed under the MIT License.
Feel free to explore, modify, and share!
Add your own .html
, .css
, .png
, or .js
files into the public/
directory and access them via your browser. The server will serve them just like a real production web server.