Code Monkey home page Code Monkey logo

webserver's Introduction

Multi-threaded web server

A multi-threaded (e.g. file-based) web server with thread-pooling implemented in Java.

Any class that implements WebApp interface can be plugged as the handler application. In this example I'm using FileServingApp (serves static files from a document root) as my handler application. The single method that must be implemented is HttpResponse handle(HttpRequest request).

Request flow

  1. Server receives a request.
  2. Server creates a Handler (Runnable) for this request.
  3. Handler parses the request into a HttpRequest.
  4. Handler passes the HttpRequest to the handler application.
  5. Handler writes the response received from the handler application to the output stream.
  6. Handler closes the streams.

A compiled version webserver-1.0-SNAPSHOT.jar can be found in the root directory.

WebServer - listens for connections and delegates them to worker threads.

Handler - handles a single request, by parsing it and sending it to the handler application.

ExecutorMonitor - prints server status once every 10 seconds.

FileServingApp - an application that serves static files from it's document root.

Installation

gradle build

Usage

java -jar webserver-<version> <port> <threads> <document root>

webserver's People

Contributors

warchildmd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.