Here’s a complete README.md
for your HTTP server project:
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.
- 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).
- 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
Follow these steps to build and run the project:
Before starting a new build, it's a good practice to clean previous build files:
rm -rf CMakeCache.txt CMakeFiles
Use CMake to configure the project with GCC as the compiler:
cmake -G "Unix Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..
Build the project using the following command:
cmake --build .
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
.
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.
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
.
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
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>";
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.
This project is licensed under the ISC License. You are free to use, modify, and distribute this software under the terms of the license.