I worked with HTTP Servers for a long time but I never tried to explore how an HTTP server works, so let do it together.
What is an HTTP server actually?
A server which runs in a computer to serve HTTP request from remote browsers.How it works?
As a user when we type an URL (Unified Resource Locator) in our browser it sends an HTTP request to the internet then it forwarded to the concerned server, the server process the request and send back HTTP response to the client browser.Okay, it sounds simple to make HTTP server work.
Let's get into it.
A Server class which creates a server program, do initial setup for web server operation like port number, file directory etc then it run in an infinite loop and wait for requests.
A Server class which creates a server program, do initial setup for web server operation like port number, file directory etc then it run in an infinite loop and wait for requests.
In request object we are going to process the HTTP request coming from client browsers. In Request.java class we are going to process the request and see the URLs browsers are requesting are valid or not.
In request class we are read the request from socket request stream and striping up the requested page name.
In request class we are read the request from socket request stream and striping up the requested page name.
Now let work on HTTP response. In this class we create a response and send it back to requesting browser.
So what we are doing here is we are looking at a specific location where all the web files should be present and if the requested page found then simply write it to socket output stream.
Source Code of SimpleHttpWebServer
So what we are doing here is we are looking at a specific location where all the web files should be present and if the requested page found then simply write it to socket output stream.
Source Code of SimpleHttpWebServer
Welcome to Anindya's Simple Web Server |