Skip to content

codejasleen/Multithreaded-HTTP-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Multi-threaded HTTP Server

Description

This is a simple multi-threaded HTTP server implemented in Python for a Computer Networks project. It serves static files from the resources directory and supports file uploads via POST requests.

Features

  • Multi-threaded architecture with a fixed-size thread pool
  • Supports GET requests for static files (HTML, TXT, PNG, JPG, JPEG)
  • Supports POST requests to /upload for JSON data
  • Keep-alive connections
  • Security features: path traversal protection, host validation, content-type checks
  • Logging of requests and responses

Requirements

  • Python 3.x

Installation

Clone or download the project files.

Build Instructions

No build required. This is a pure Python script using only standard library modules. Ensure Python 3.x is installed.

Usage

Run the server with default settings:

python server.py

Or specify host, port, and number of threads:

python server.py [port] [host] [threads]

For example:

python server.py 8080 127.0.0.1 10

Prerequisites: Ensure the resources directory exists (it will be created automatically if missing). To stop the server, press Ctrl+C. Test the server by opening http://127.0.0.1:8080 in a browser or using curl for API endpoints.

Project Flow

A simplified overview of the server's request handling flow:

Client Request
      |
      v
Accept Connection (Main Loop)
      |
      v
Queue to Thread Pool
      |
      v
Parse & Validate Request (Host, Path, Security)
      |
      v
Handle Request:
- GET: Serve Static File
- POST: Upload JSON to /upload
      |
      v
Send Response (Headers + Body)
      |
      v
Log & Manage Connection (Keep-Alive or Close)

For a detailed architecture diagram, see project_summary.md.

File Structure

  • server.py: Main server script
  • resources/: Directory containing static files
    • index.html: Home page
    • about.html: About page
    • contact.html: Contact page
    • sample.txt: Sample text file
    • logo.png: Logo image
    • photo.jpg: Photo image
    • uploads/: Directory for uploaded files

API Endpoints

  • GET / : Serves index.html
  • GET / : Serves static files
  • POST /upload : Accepts JSON data and saves to uploads/

License

None specified.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published