Skip to content

A simple HTTP 1.1 Web server made using C and Sockets sys calls in Linux

Notifications You must be signed in to change notification settings

Tony-ArtZ/c-http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple C Web Server

This project is a basic web server written in C that serves static files (HTML, CSS, images, etc.) over HTTP. The server listens on port 8080 and handles GET requests to serve files from the project directory.

Features

  • Serves static HTML, CSS, JavaScript, and image files.
  • Basic MIME type detection based on file extensions.
  • Handles GET requests and returns 404 for missing files.
  • Built using low-level socket programming and system calls.

Directory Structure

├── MakeFile         # Compilation instructions
├── a.out            # Executable (optional, can be ignored)
├── about.html       # Sample HTML file
├── handler.c        # Handles incoming client requests
├── index.html       # Main page served by the server
├── main.c           # Entry point of the server program
├── mime.c           # MIME type detection based on file extension
├── public/          # Static assets (CSS, images)
│   ├── index.css    # Stylesheet
│   └── space.jpg    # Example image
├── server.c         # Socket setup and HTTP response handling
├── server.h         # Header file for shared function prototypes

Compilation and Execution

Prerequisites

  • You need to have gcc and make installed on your system. If you are using Ubuntu in WSL, you can install them with:

    sudo apt update
    sudo apt install build-essential

Build the Project

You can compile the project using the provided MakeFile:

make

This will generate an executable named server.

Running the Server

After compiling, you can run the server with:

./server

The server will start listening on localhost:8080.

Accessing the Server

Once the server is running, open your web browser and navigate to:

http://localhost:8080

You can view the index.html or other files in the directory. For example, you can also access:

http://localhost:8080/about.html
http://localhost:8080/public/index.css
http://localhost:8080/public/space.jpg

Clean Up

To remove the compiled files (object files and executables), run:

make clean

Releases

No releases published

Packages

No packages published