So we will discuss in the next example, which is a little bit more complicated example of implementing
a TCP server.
In that example, our TCP server actually would have the capability to handle multiple clients at the
same time.
It means that our TCP server would be maintaining multiple communication file descriptors to carry out
communication with multiple clients.
So in that example we will see that our TCP server would maintain.
A set of file descriptors using the data structure fd underscore set.
And there it will be more clear to you that what is the potential use of this data structure?
So guys, let's have a demonstration of the TCP client and the Dhcp server that we have just studied
so far.
So on the left hand side, I will start the TCP client.
So you can see that we have a TCP client dot C file.
You need to compile this file using GCC
minus O and TCP client.
So the TCP client program is compiled.
You can see that it creates an executable TCP client.
You can simply run the TCP client.
But before running the TCP client, let's start the TCP server.
So you need to compile the TCP server also.
Remember the TCP server functionality is implemented in TCP servers.
So I will compile this file.
So it will create a TCP server executable here and you can simply execute this executable.
So our TCP server has started and it is blocked on the system.
Call select.
Right now.
Let's start with the TCP client.
So here you can see that as soon as I start the TCP client, it created its communication file descriptor
and immediately send the connection initiation request to the server.
So you can see that the server has received the connection request from the client from IP address.
127.0.0.1 and the port number that is assigned by the operating system to the client is 43930.
So we can see that the client IP address is 127.0.0.1, which is nothing, but it is a localhost.
That is the default IP address of your same machine.
So basically you can run the client and the server program in different terminal windows and they can
carry out communication with each other using the IP address.
127.0.0.1.
Now the client is asking the user to enter the value of a.
Let's say we enter the value of A as ten and the value of B as 20.
So you can see that server has received something from the client.
That is, it received the values of A and B, and then it add these values and send back the result
to the client.
So the client receives the addition of these two values as 30.
And again, the client is now prompting the user to enter the values of A and B.
So you can see that the communication is happening between the client and the server program.
You can run the TCP server as well as TCP client on different virtual machines on your setup if you
have created a topology.
But in that case the IP address.
127.0.0.1 will not work.
You will have to really specify the right IP address of TCP server process.
As you can see in this example, if you run the TCP server process on a separate virtual machine, you
will have to specify the IP address, which is equal to the IP address of any local interface of that
server machine.
It could be IP address of any local interface, including loopback interfaces.
And yes, you have to choose a port number to be assigned to your Dhcp server.
So this was a demonstration for you to how to compile and run the Dhcp server and Dhcp client program
on the same machine.
Or you can choose different machines.
Now next we will going to discuss our Dhcp server design in which the Dhcp server can actually maintain
the multiple connections from multiple clients and at the same time can reply and serve those multiple
clients at the same time.
As of now, our TCP server has a limitation that it cannot communicate or entertain more than one client
at a time.
For example, you can see that our TCP server is actually communicating with this client.
Let us say that there comes another client.
You can create a new window.
So you can see that I can run the client that is the same client executable but in different window.
So it is as good as you are starting a new client.
And as soon as you execute this new client in the new window, you can see that our server do not respond
to this client.
The reason is that at this point of time our server is blocked on receive from system call.
Our TCP server would reply and respond back to the new client only when our TCP server would have blocked.
On select system call.
And monitoring the master socket file descriptor in order to detect new client connection initiation
requests.
But at this point of time our TCP server is blocked on receive from system call, so it cannot detect
any new client connection request.
And that is the reason that our TCP server do not respond to this new client.
Right.
So next example, we will going to discuss the TCP server which could handle multiple clients and such
a TCP server is called TCP server with multiplexing.