So, guys, next we will going to discuss the implementation details of Http web server.
So let's have a code walk regarding how to implement the Http web server.
So implementing the Http web server is no different than implementing a normal TCP server.
We have already discussed the steps to implement a normal TCP server, so you will see that the code
of Http web server is almost 90% same as that of normal TCP server.
Right.
The only difference is that as Http server expects the client data as per Http standards, that is,
the client has to send the data to the Http server either as a post request or as a get request or some
other request that is defined by Http standards and Http server.
On the other hand, prepare the response as per the Http standards only.
So we have already discussed in the previous two slides that Http client and the Http server they communicate
based on predefined message formats.
Right.
So prerequisite to understand the Http server code is that you should know a little bit of HTML, just
a little bit of HTML.
Even if you don't know for the sake of understanding that how Http server are designed, you can still
take up this code walk.
And of course you should know how STR talk function in C works.
So just to give you a brief about this function, this function is used to generate tokens.
So tokens means for example, suppose you have some strings, for example, a quick.
Brown fox jumps over the lazy dog.
Okay, let's stop here.
A quick brown fox jumps over.
Right.
So here you can see that each word in this string is separated by a space.
Right.
So you can use STR function to split this string and generate tokens based on space.
So space works as a delimiter, and the tokens are individual words.
So the STR function can give you tokens.
The first token will be a, the second token will be quick, the third token will be brown, the fourth
token will be fox and the fifth token will be jumps and the sixth token will be over.
So you can see that this string is splitted based on space as a delimiter.
So this is what STR function in C works.
It can split a given string based on a certain delimiter.
Delimiter.
Right.
So in this example, our delimiter is space.
You can download the code from this.
Earl.
In this directory that is server design.
You can navigate to a directory, web server, and inside the web server directory you have TCP web
server directory.
And inside this directory you have a TCP web server dot c file, which is the implementation of Http
web server.
And as you know that in Http web server client model, the client is nothing but a browser.
So you don't have to write any dot C file to implement Http client functionality, right?
Because your client itself is a browser.
So going forward, let us take an example of Http web server functionality that we will going to discuss.
So we have picked up a Http web server with a very minimal functionality.
The simple functionality is that that a web server maintain the database called student database.
Right?
So in this database, the Web server stores the details of students, right.
So what we do in this example that we will query the web server with the student role number as a key.
So using this key, the Web server will search in its student database and find the student which matches
the role number and simply the web server returns the student info to the browser, and the browser
simply displays the information that is returned by the web server in the response.
So this is the simple example that we will going to discuss.
So guys, you can see that I am in this directory which contains the file TCP web server dot c.
So this file implements the functionality of our Http web server.
So before diving deep into the discussion of the code, let us have a quick demonstration of how our
Http web server works.
So first of all, I will compile this program.
So I will compile this program simply by using GCC compiler.
And if you see that it has created the executable.
So simply run this executable and our Http web server has started and it is blocked on select system
call.
That is, it is now waiting for the client connection request.
So as I said in this example, the client is nothing but it is our Http.
But it is our browser.
So in this browser I will type out the URL so you can see that I have typed out the URL in the browser.
So let us see the format of this URL.
So 192.168.56. 100 is the IP address of the virtual machine because you can see that the browser I have
opened is on Windows, right?
And the Http server is running on virtual machine.
So it is as good as like two machines connected with each other.
The first machine is windows and the second machine is virtual machine.
So if you use windows, you have to specify the IP address.
192.168.56. 100, which is the IP address of your virtual machine.
Otherwise, alternatively, if you don't have a connectivity between your.
Between your virtual machine and Windows Operating system, which is a host.
Operating system.
Then you can open a browser inside your virtual machine only.
And instead of 192.168. 5600, just specify the IP address.
127.0.0.1.
Right.
Because I'm using a browser on the Windows machine.
Therefore I have to specify the actual IP address of the virtual machine.
Right.
So after the IP address, I have specified the port number on which my Http web server is listening.
Right.
So remember our Http web server is nothing, but it is a normal Dhcp server.
So I have open a TCP socket and bind that socket with the port number 2000.
Right.
And after that following is the URL which actually identifies a resource I am trying to query from the
server.
So Http requests have this format.
That is after port number using slash backslashes.
You can separate the words.
And after question mark, you can specify the parameters.
Which you can vary and query different different data from the server.
So in this example, I'm trying to query the student, the details of the student.
Who is in Department CSC and has a roll number 10305042.
So the moment I press enter, you can see that my TCP server has sent me the HTML response and the HTML
response is nothing, but it is an HTML code which the browser understands and the browser has executed
that HTML code and as per that HTML code, the browser simply prints the name of the student.
So I have implemented the functionality on the Http server such that when it receives the query from
the client, it simply returns a table of one row and one column, and inside that row and column written
is the name of the student.
So simply my Http web server is working.
Right.
So you want to query it again?
Just copy the URL, open the new tab and close the older tab.
The reason is that that the Http web server that I have implemented can handle only one client at a
time.
Right, because I have not used multiplexing.
So that is the reason that before querying the next data or before sending the next request to the server,
close the older tab in the browser.
The closing of the tab corresponds to.
Sending the close connection request to the server so the server closes the older connection and is
now ready and is waiting on the select system.
Call for the new connection request from the client.
Now here you can vary the parameters.
And you can see that the server has now given me another name.
Right.
So our Http web server is working.
As I said, that if you open a browser on your virtual machine, then instead of this IP address, just
specify 127 .0.0.1 and.
And it will just work fine.
Of course you can enhance the Http web server design into a multiplexed http web server, which could
handle multiple client connection requests at the same time.
Right.
But for understanding purpose, I have just taken the TCP server which could handle only one client
at a time and enhance the functionality of that Dhcp server to behave as as a Http web server.
So now let's see how we have enhanced the functionality of a normal TCP server and converted it into
Http web server.