This project is a minimalist, educational HTTP server built directly on Python's native socket library.
The primary goal is to gain a deep, practical understanding of fundamental computer networking concepts, specifically how the Application Layer (HTTP) interacts with the Transport Layer (TCP), without relying on high-level frameworks like Flask or Django.
This project serves as a hands-on exercise to master the following core concepts:
- TCP Socket Programming: Implementation of the standard Client-Server communication model using
socket.socket(socket.AF_INET, socket.SOCK_STREAM).- Demonstrates the workflow:
bind()->listen()->accept().
- Demonstrates the workflow:
- Request/Response Cycle: Manually handling the complete HTTP/1.1 transaction flow:
- Receiving and parsing the raw byte stream from the client (
client_socket.recv()). - Extracting the HTTP Method and Request Path.
- Manually constructing a compliant HTTP Response (Status Line, Headers, and Body).
- Transmitting the response using
client_socket.sendall().
- Receiving and parsing the raw byte stream from the client (
- Protocol Compliance: Understanding and adhering to the necessary formatting for an HTTP response, including the use of
\r\nline endings and the critical role of theContent-Lengthheader.
- Python 3.x
- Ensure an
index.htmlfile exists in the root directory for the server to serve.
- Clone this repository or navigate to the project directory.
- Start the server from your terminal:
python main.py
- Access the server in your browser:
http://localhost:8080
- Implement basic multi-threading or non-blocking I/O to handle multiple concurrent client connections.
- Add logic to serve common static file types (e.g.,
.css,.js,.png) based on the requested file path. - Introduce robust error handling for broken pipes and malformed requests.