This is a simple web server implemented in C that serves static files such as HTML, CSS, JavaScript, images, videos, and PDFs. The server listens on port 8080 and handles basic HTTP GET requests.
- Static File Serving: The server can serve static files like HTML, CSS, JavaScript, images, videos, and PDFs.
- Basic Error Handling: The server responds with
404 Not Foundfor missing files and405 Method Not Allowedfor unsupported HTTP methods. - MIME Type Detection: The server automatically detects the MIME type of the requested file based on its extension.
- Multi-Client Support: The server can handle multiple client connections sequentially.
- server.c: The main C file containing the web server implementation.
- index.html: The default homepage served by the server.
- about.html: A sample "About" page.
- contact.html: A sample "Contact" page.
- 404.html: A custom 404 error page displayed when a requested file is not found.
-
Clone the Repository:
git clone https://github.com/Keeththi2003/Webserver-in-C.git cd Webserver-in-C -
Complie the Server:
gcc server.c -o server
-
Run the Server:
./server
-
Access the Server: Open your web browser and navigate to
http://localhost:8080/.
The server supports the following file types:
- HTML:
.html - CSS:
.css - Javascript:
.js - Images:
.jpg.jpeg.png - Video:
.mp4 - Audio:
.mp3 - PDF:
.pdf
- 404 Not Found: If a requested file does not exist, the server responds with a custom
404.htmlpage. - 405 Method Not Allowed: If an unsupported HTTP method is used (e.g., POST), the server responds with a
405 Method Not Allowederror.
-
Port: You can change the port the server listens on by modifying the PORT constant in
server.c. -
Error Pages: You can customize the
404.htmlpage or add other error pages as needed. -
File Types: You can extend the
getFileTypefunction inserver.cto support additional file types.
-
This server is designed for educational purposes and is not suitable for production use.
-
It does not support advanced HTTP features like caching, compression, or HTTPS.
-
It handles one client at a time and does not support concurrent connections.(In the future, I will upgrade te server to support multi-threading, allowing it to handle multiple clients concurrently.)
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.