A simple, multi-threaded HTTP server implementation in Java that demonstrates basic web server concepts including request handling, routing, and concurrent client connections.
- Multi-threaded: Uses a thread pool with 8 threads to handle concurrent client connections
- Basic Routing: Supports multiple endpoints with different content
- HTTP/1.1 Compatible: Implements basic HTTP protocol standards
- Lightweight: No external dependencies, uses only Java standard library
Architecture
graph TD
Clients[Client Requests] --> ServerSocket[Server Socket]
ServerSocket --> ThreadPool[Thread Pool]
ThreadPool --> Thread1[Thread 1]
ThreadPool --> Thread2[Thread 2]
ThreadPool --> Thread3[...]
ThreadPool --> Thread8[Thread 8]
Thread1 --> Handler1[RequestHandler]
Thread2 --> Handler2[RequestHandler]
Thread8 --> Handler8[RequestHandler]
Handler1 --> Response1[ResponseGenerator]
Handler2 --> Response2[ResponseGenerator]
Handler8 --> Response8[ResponseGenerator]
Response1 --> ClientResponse1[Response]
Response2 --> ClientResponse2[Response]
Response8 --> ClientResponse8[Response]
- / : Home page with navigation links
- /about : Information about the server
- /random : Generates a random number (1-100)
- /stats : Displays server statistics
- Other routes :Returns 404 Not Found
- Compile the Java files:
javac HttpServer.java RequestHandler.java ResponseGenerator.java- Run the server:
java HttpServer- Access the server: Open your browser and navigate to http://localhost:8080