
									 Problem
								
								
									 Solution
								
								
									 Submissions
								
								
							Multi-threaded Web Server
								Certification: Advanced Level
								Accuracy: 100%
								Submissions: 2
								Points: 15
							
							Write a Python program to implement a multi-threaded web server that can handle multiple client requests concurrently. The server should be able to serve static files from a specified directory and handle basic HTTP requests.
Example 1
- Input:
 server = WebServer(port=8080, document_root="./www")
 server.start()
 # Client: GET /index.html HTTP/1.1
- Output:
 HTTP/1.1 200 OK
 Content-Type: text/html
 Content-Length: 325
 ...<html><head><title>Welcome</title></head><body><h1>Hello World!</h1></body></html>
- Explanation:
- Server returns index.html from document root.
- Includes correct HTTP headers.
 
Example 2
- Input:
 # Client: GET /nonexistent.html HTTP/1.1
- Output:
 HTTP/1.1 404 Not Found
 ...<h1>404 Not Found</h1><p>The requested resource was not found.</p>
- Explanation:
- 404 error page returned for missing file.
 
Constraints
- ≥ 50 concurrent connections
- Max static file size: 100MB
- Response time ≤ 500ms
- Supports .html, .css, .js, .jpg, .png, .gif
- Time Complexity: O(n)
- Space Complexity: O(m)
Editorial
									
												
My Submissions
										All Solutions
									| Lang | Status | Date | Code | 
|---|---|---|---|
| You do not have any submissions for this problem. | |||
| User | Lang | Status | Date | Code | 
|---|---|---|---|---|
| No submissions found. | ||||
Solution Hints
- Use Python's socket module to create a TCP server
- Implement threading with Python's threading module
- Create a thread pool to limit and manage concurrent connections
- Parse HTTP requests and generate appropriate HTTP responses
- Use file I/O operations to read static files from the document root
