So guys, let us discuss some observations regarding the TCP client server program that we have just
discussed.
So the TCP client server design that we just discussed, it had certain drawbacks.
Let us discuss those drawbacks.
So in this design we see that the server cannot accept other clients request while it is processing
the current client.
Right.
So why it was happening?
Because when the server had booted up, right as soon as the server boots up it creates a master socket
file descriptor and after creating a master socket file descriptor, the server make a call to a select
system.
Call and select system call is a blocking system call.
Right?
So when the server boots up, it gets blocked immediately at a select system call after creating a master
socket file descriptor.
Now, at this point of time, if any client C sends a connection request to the server.
Then the server gets unblocked from the select system call and immediately calls an accept system call.
The Accept System call creates a communication file descriptor using which the server communicates with
the client for the rest of the lifetime of the connection.
So as soon as the communication file descriptor is created using accept system call, the server makes
a call to the receive from system call.
That is, the server waits for the data from the client.
So the server gets blocked at the stage three.
That is, the server is waiting for the data from the client.
So let us call this client as C1.
Now at this point of time, that is when the server is in stage three.
Suppose there is another client, C2, which again sends a connection request to the server.
Now because the server is blocked in the stage three The server do not entertain the connection request
from the client see to.
Right.
So this was the drawback in our TCP client and server design that we had just discussed because the
server is waiting for the data from the client.
C1 That is, the server is blocked at the stage three.
The server s cannot entertain any other client.
Right.
So because of this.
This TCP server had a drawback that it can entertain only one client at a time.
Right.
So when the client C1 sends the data to the server.
Now, note that it is not a connection request, but it is a data, so the server moves from the stage
three to the stage four.
Right and at the stage for the server can process the client data and reply back to the client even
after replying back to the client.
Even the server again moves back to the stage three.
So you can see that the server is oscillating between the stage three and four.
And while the server is oscillating between the stages three and four, the server is entertaining only
the client C1.
So the type of design that we had just discussed is a design in which the server can entertain only
one client at a time.
Right because the server can entertain another another client only when the server is blocked at the
select system call.
But in this design, once the server receives the connection request from the client C1 the server Unblocks
from the select system call and get stuck between the stage three and four forever.
Right.
So this is the reason that in this design the server cannot entertain more than one client.
Right.
So you must be thinking then what is the use case of such a design?
So it's not like that that this design is useless.
This design is still useful in the scenario where there is only one client to be served by the server.
So this kind of design is used where there is only one and only one dedicated client of a server.
Such server processes are used in system softwares where there is only one client and one server.
This server design cannot handle multiple clients connections that we have discussed.
So remember, servers are just another process which accepts some data from another process.
So nothing is special, right?
Servers are just another processes which can accept the data from another processes which are called
clients and can process that data and return back the result.
So such a machine which accepts the data, process the data and return the result are usually called
are usually termed as server machines.
Server doesn't generate any data.
That means server doesn't generate any data by itself.
Server has the property that they just replies to the client after processing the client's data.
Server by themselves never sends message to the client without client's initiation first.
So this is the basic property of the server.
So now we have discussed how to write a TCP server which can entertain only one client.
Let us now discuss how to write a TCP client program.
So writing a TCP client is fairly easy as compared to writing a TCP server, right?
And after that we will going to discuss the design of a TCP server in which the server can actually
handle multiple clients at the same time.