A multi-threaded HTTP server built using socket programming in Python, demonstrating low-level networking concepts and HTTP protocol implementation.
- Multi-threaded request handling with thread pool
- Binary file transfer support (PNG, JPEG, TXT files)
- HTML file serving with proper Content-Type headers
- JSON POST request processing
- HTTP/1.1 keep-alive connection support
- Path traversal protection and security features
- Python 3.6 or higher
Basic usage (localhost:8080):
python3 server.pyCustom port:
python3 server.py 8000Custom host and port:
python3 server.py 8000 0.0.0.0python3 server.py [port] [host] [max_threads]
port: Port number (default: 8080)host: Host address (default: 127.0.0.1)max_threads: Maximum thread pool size (default: 10)
Socket-P/
├── server.py # Main HTTP server implementation
├── resources/ # Web content directory
│ ├── index.html # Home page
│ ├── about.html # About page
│ ├── contact.html # Contact page
│ ├── sample.txt # Test text file
│ ├── logo.png # PNG image
│ ├── photo.jpg # JPEG image
│ └── uploads/ # Directory for POST uploads
└── README.md # Documentation
Open your browser and navigate to:
http://localhost:8080/- Home pagehttp://localhost:8080/about.html- About pagehttp://localhost:8080/contact.html- Contact page
curl -O http://localhost:8080/sample.txt
curl -O http://localhost:8080/logo.png
curl -O http://localhost:8080/photo.jpgcurl -X POST http://localhost:8080/upload \
-H "Content-Type: application/json" \
-d '{"name": "test", "message": "Hello World"}'- Path Traversal Protection: Blocks attempts to access files outside the resources directory
- Host Header Validation: Prevents host header injection attacks
- Request Size Limits: Prevents DoS attacks
- Input Validation: Validates JSON data and file paths