Skip to content

A simple and modular HTTP server built in Java that supports multithreading, directory listing, and static file serving. Perfect for learning how servers work and handling basic web requests without using external frameworks.

Notifications You must be signed in to change notification settings

san-rizz-777/Java_HTTP_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โ˜• Java HTTP Server

A minimal yet modular HTTP server in Java built from scratch โ€” supports:

  • ๐Ÿงต Thread pool based on available CPU cores
  • ๐Ÿ“ Directory listing
  • ๐Ÿ›‘ Graceful shutdown
  • ๐Ÿ“„ Static file serving (HTML, CSS, JS, images)
  • ๐Ÿงฑ Modular structure (Server, Handler, Utilities)

๐Ÿš€ How to Run

Prerequisites

  • Java 8 or later
  • IDE like Eclipse, IntelliJ, or CLI (javac + java)

Steps (Eclipse)

  1. Clone this repo or download the source.
  2. Open Eclipse โ†’ Create New Java Project
  3. Inside src/, create a package called server
  4. Copy the .java files into src/server/
  5. Create a folder public/ (outside src/) and place an index.html
  6. Run SimpleHTTPServer.java
  7. Open http://localhost:8080

๐Ÿ“ Directory Layout

SimpleJavaHTTPServer/

  1. โ”œโ”€โ”€ public/ # Static files to serve โ”‚ โ””โ”€โ”€ index.html
  2. โ”œโ”€โ”€ src/ โ”‚ โ””โ”€โ”€ server/ โ”‚ โ”œโ”€โ”€ SimpleHTTPServer.java โ”‚ โ”œโ”€โ”€ ClientHandler.java โ”‚ โ””โ”€โ”€ HTTPUtils.java
  3. โ”œโ”€โ”€ README.md

๐Ÿ”ง Features

Feature Description
๐Ÿ”„ Thread Pool Uses Runtime.getRuntime().availableProcessors() for scalable performance
๐Ÿ“ Directory List Lists folder contents via dynamic HTML
๐Ÿงฑ Modular Code Separated into server, handler, utility classes
๐Ÿ›‘ Graceful Stop Shutdown hook handles Ctrl+C or Eclipse stop button cleanly
๐Ÿ“„ Static Serving Serves HTML, CSS, JS, images from public/ folder

๐Ÿ”ฎ Future Ideas & Improvements

  • ๐Ÿ”„ Support for POST requests and form submissions
  • ๐Ÿ” Add basic authentication or IP filtering
  • ๐Ÿ“ Implement logging (to console or file)
  • โš™๏ธ Add config file for port, base directory, max threads
  • ๐Ÿงช Add unit tests for handlers and utility methods
  • ๐Ÿ“ฆ Support MIME upload/file download features
  • ๐ŸŒ Enable CORS headers for cross-origin support

๐Ÿ“ฌ Feedback & Contact

Have suggestions, feedback, or want to collaborate?

Feel free to reach out for Java backend projects, internships, open-source collaboration, or tech chats!

About

A simple and modular HTTP server built in Java that supports multithreading, directory listing, and static file serving. Perfect for learning how servers work and handling basic web requests without using external frameworks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published