Skip to content

This project is a simple HTTP server implemented in C using the **C_STD** framework. It demonstrates basic server setup, handling client requests, and serving HTTP responses. The project is designed to be a learning resource for C programmers and a demonstration of how to build network-based applications using C.

License

Notifications You must be signed in to change notification settings

KaisenAmin/http_server_c_std

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Here’s a complete README.md for your HTTP server project:

HTTP Server in C using C_STD Framework

This project is a simple HTTP server implemented in C using the C_STD framework. It demonstrates basic server setup, handling client requests, and serving HTTP responses. The project is designed to be a learning resource for C programmers and a demonstration of how to build network-based applications using C.

Table of Contents

Features

  • Serves static HTML content over HTTP.
  • Handles multiple client connections sequentially.
  • Built using the C_STD framework for enhanced C development.
  • Cross-platform support (Windows and Linux).

Requirements

  • GCC compiler (ensure it's added to your system's PATH).
  • CMake for building the project.
  • OpenSSL (for SSL/TLS functionality, if needed).
  • Linux Users: Ensure you have development libraries installed:
    sudo apt-get install libssl-dev

Build and Run

Follow these steps to build and run the project:

1. Clean Previous Builds

Before starting a new build, it's a good practice to clean previous build files:

rm -rf CMakeCache.txt CMakeFiles

2. Configure the Project

Use CMake to configure the project with GCC as the compiler:

cmake -G "Unix Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..

3. Build the Project

Build the project using the following command:

cmake --build .

4. Run the Server

After building, run the HTTP server:

make run

If everything is set up correctly, the server will start and listen on localhost at port 8051.

Usage

Accessing the Server

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

http://localhost:8051

You should see a simple HTML page served by the server.

Handling Client Requests

The server handles GET requests and responds with a basic HTML page. The logic for handling client requests is defined in the handle_client_request function in main.c.

Customization

Changing the Server Port

You can change the server port by modifying the SERVER_PORT macro in main.c:

#define SERVER_PORT 8051  // Change this to your desired port

Serving Different Content

To serve different content, modify the response string in the handle_client_request function:

const char* response = 
    "HTTP/1.1 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Connection: close\r\n"
    "\r\n"
    "<!DOCTYPE HTML>"
    "<head><title>Custom Title</title></head>"
    "<body><h1>Custom Content</h1><p>Your content here.</p>"
    "</body>"
    "</html>";

Enabling SSL/TLS

To enable SSL/TLS, you will need to modify the project to include SSL handling in the TCP connection. This involves using OpenSSL and modifying the server to handle SSL handshakes and encrypted communication.

License

This project is licensed under the ISC License. You are free to use, modify, and distribute this software under the terms of the license.

About

This project is a simple HTTP server implemented in C using the **C_STD** framework. It demonstrates basic server setup, handling client requests, and serving HTTP responses. The project is designed to be a learning resource for C programmers and a demonstration of how to build network-based applications using C.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published