So guys let us
Understand the concepts that we have discussed so far by actual doing the implementation
So we will going to implement our application protocol which is nothing but we will going to implement our own
HTTP web server
so HTTP web server is nothing but it's a
application protocol
So we shall implement a simple client-server program which implement our own application protocol
So let us learn how to implement application protocol by implementing our own minimal
HTTP web server
So let us first understand how the HTTP web server actually works. So
You can see in this diagram
The machine on the left-hand side is actually the client machine. Whereas the machine on the right-hand side is actually the web server
Then
When you browse the Internet
How does the actually page loads when you click a certain link or when you browse certain web sites?
So let us go through the steps
Regarding how the HTTP protocol works
So the HTTP web server works as per the following steps
So the client first of all
the client here is nothing, but it's a browser so
the client prepares the HTML request message
so the HTML request message something looks like this. it has a
URL as
Well as the final resource, which the client wants to fetch from the server in this case
The final resource is the image of Acer laptops. That is Acer.IMG
Right, so the client needs to know the location of the resource, It is trying to fetch from the web server
So csepracticals.com actually resolved to the IP address of the server machine
Right and on the server machine
There is a folder images. Inside that images there is a folder laptop and inside that laptop
There is a image file acer.img. So this entire path actually
Represents the location of a resource present on the internet uniquely
So here the resource is the image file so
This HTML request message is actually the application
payload
This application payload is then pushed
down the tcp/ip stack on the client side
Right. So as the payload is
Pushed down the tcp/ip stack, the intermediate layer So the tcp/ip stack adds their own respective headers
Then client machine sends the HTTP request to the server asking for
Some information that is asking for a resource. So you can see this HTTP request actually
traverses through the internet that is through l3 routing and finally this HTTP request reaches the server
When the server receives this HTTP request this request moves up in the tcp/ip request on the server machine
So this is the step four and as the message traverses
Upwards in the tcp/ip stack on the server machine each of these layers
chop off their respective headers from the message and
finally the
HTTP payload is delivered to the web server application running on the server machine
Then in the next step the server do the processing as per the client request
So in the step 6 the server prepares the HTML response
so HTML response means it generates the HTML code and
This HTML code
is
What forms the reply to the HTTP request
Generated by the client
So this HTML response forms the application payload from the server side
Then this HTML response is pushed down the tcp/ip stack on the server side and
Finally it is routed back to the client
Right
This HTML response is then pushed up in the tcp/ip stack and finally the browser that is the client receives
The HTML response that is generated by the web server
so remember the HTML response was nothing but it was a HTML code and our client is nothing but it is a browser so
Browser understands HTML code that is using this HTML code
Which the browser has received in the HTML response from the web browser, the browser
renders the page
So in the step 10 finally the browser renders the page which is HTML code
So this is how the
HTTP web server works
Now let us try to understand the implementation details of HTTP web server
So we have just discussed that the HTTP client sends the HTTP request to the server
So the HTTP client requests are of several types
The request that is generated by HTTP client are of several types. We will going to discuss two most commonly used ones
You should Google as HTTP request methods to learn for more of them
So there are not two there are actually six or seven types of HTTP client requests
We cannot discuss all of them here, but we will discuss the two most commonly used HTTP requests
That is the get request and the post request
So after you understand the implementation of HTTP web server
You can browse the Internet to learn other type of HTTP requests
You can implement them as a part of your coding assignment
But before that let us build the basics
So what are actually get request? Get request as the name suggests
The client is trying to fetch or get the data from the server
so example of get request is like you are entering the roll number on the web page and
In return you are getting your exam result
or the most simple get request is that
Clicking the links and load or navigate to a new page
So all of these are the example of get request
Get request are concerned with fetching the data from the server
The other type of request is the post request. the post requests are concerned with sending the data to the server
Which will be eventually saved on the server side. For example, you are filling up the job forms
So you fill up all your details in the form and then you click Submit
Right. So all your details get saved on the server
another example is uploading your resumes and
Other examples are such that you are posting any comment or any post on certain social sites such as Facebook
So in all this example one thing is common that you are sending the data to the server and the server
eventually stores that data
So such type of request that is made by the HTTP client are called post requests
So when HTTP client sends the HTTP request to the server client has to encode the request type in the request
right
Otherwise how the server would come to know whether it has HTTP GET request or it is HTTP post request
So next let us discuss the exact format of HTTP GET request message
When HTTP client sends the HTTP request to the server
Whether the request is a get request or post request, it sends the HTTP request in a
predefined or standard format
So the HTTP request that is the get or post or any other
HTTP requests have to be in the
defined or standard format
Just like you have IP header in the standard format
The HTTP requests are also have their own specific and standard format
So let us take an example of HTTP get request that is how does HTTP GET request look like.
So below is the HTTP get request
message contents
so you can see that the HTTP request looks like
plain text or paragraphs so
It's a plain text
So this entire text in yellow is the HTTP GET request
The first line of the HTTP GET request is called request line
Why it is called request line
because in request line
The client specifies the resource, which it wants from the server
So here the first word is the GET
That means it is a get request
the second part of the get request is
the
Location of the resource which the client is requesting from the server
So you can see in this example
The client is actually requesting from the server
the details of the student whose roll number is 1 0 3 0 5 0 4 2 and
The department is CSC that is computer science and engineering
Right, so when the server receives this HTTP request the server will pass this
URL and come to know that what actually client is looking for and
The third part of this request line is the HTTP protocol version
Right so you can see in this get request format only what is important for you is to know the request line
format
the rest of the details are actually automatically
Generated and added by the browser
to your get request
Right, so we will learn in the practical session that how do you generate this HTTP GET request using browser
So one thing to note here is that
That HTTP message types are simple plain text strings so you can see it's a simple text
So all you need to do is to type out the request line in the browser and
the rest of the content in the HTTP GET request is
Automatically added by the browser
so this content is
auto-generated
Only the request line is what is required to be feeded by the user using the browser
So going forward
the HTTP web server replies back to the HTTP client with the
HTTP response, and this HTTP response is nothing but it is an
HTML web page
So below is the HTTP response message format returned by the web server to the client
So you can see that the HTTP response that is returned by the web server to the client is also a plain text
Right, the first line says that it is 1.1 version of the HTTP protocol
Right 200 is the code of success. That is the server is actually returning the result that was requested by the client
So 200 and ok represents the success and the server can
Also specify its own name. So the name of the server is
IIT student server and the third field is actually the content length, which is 88 bytes
So this HTML code that is returned by server is 88 bytes
right and the last field in the HTTP response header is the type of the content that is returned by the
HTTP server. so here the HTTP server is actually returning a HTML code
Right and the actual information that is returned by the
HTTP server in request of the client is actually the HTML code
Right. So it is this HTML code which is
rendered by the browser running on the client side
So you can see that the HTTP response that is generated by the server is also of
Text nature and
That is the reason that the HTTP protocol is called hypertext Transfer Protocol text means that the exchange of messages
Messages between the HTTP client and the HTTP server happens in the form of plain texts
Right, so all this is entirely a plain text so
Maybe things may not be very clear to you at this point of time. So let us do the actual implementation of HTTP web server