Skip to content

A socket http server implemented in Java with url mapping feature , which helps rapid development of web project.

Notifications You must be signed in to change notification settings

devashish234073/Java-Socket-Http-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java-Socket-Http-Server

A socket http server implemented in Java with url mapping feature , which helps rapid development of web project.

The api package contains the files required for implementing a project. And the "Runner.java" in the default package is one such implementation.

Below is the code in the main method of "Runner.java" p1

Blue box

Here first we need to create url mappings. So a "GET" request with "/" url will be served by the "index.html" page from the "html" directory.

Red box

This is another way of doing the above step where the abstract class "AbstractResponse"'s getResponse is implemented. It has dynamic behaviour as it has the handle of the "Request" object.

Green box

This is the loop that serves the incoming requests. "server.accept()" gets the request "server.sendResponse()" send the response from the mapping based on the url pattern.

Below picture shows the output at "http://localhost:8888" in the browser: p2

Below picture shows the classes (and some important portion from each) inside the api package: p2

AbstractResponse.java

This is an abstract class to provide dynamic responses through the Mappings.

Mapping.java

This class has two constructors to set url mappings. Already demonstrated above in the first image in the blue and red box.

Request.java

The parse() method in this class extracts out all the information and attribute out of request , which helps in creating dynamic web pages.

Response.java

The constructor for this takes a plain String as input and attaches the http header to it thus making it browser readable.

Server.java

This class is baically the first point to use any of the above classes.

About

A socket http server implemented in Java with url mapping feature , which helps rapid development of web project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published