WEBVTT

00:05.410 --> 00:14.500
So guys, let us discuss some observations regarding the TCP client server program that we have just

00:14.500 --> 00:15.550
discussed.

00:16.300 --> 00:23.620
So the TCP client server design that we just discussed, it had certain drawbacks.

00:23.710 --> 00:26.200
Let us discuss those drawbacks.

00:27.380 --> 00:34.280
So in this design we see that the server cannot accept other clients request while it is processing

00:34.280 --> 00:35.660
the current client.

00:36.110 --> 00:36.800
Right.

00:36.800 --> 00:38.480
So why it was happening?

00:38.480 --> 00:46.700
Because when the server had booted up, right as soon as the server boots up it creates a master socket

00:46.700 --> 00:54.290
file descriptor and after creating a master socket file descriptor, the server make a call to a select

00:54.290 --> 00:54.650
system.

00:54.650 --> 00:59.330
Call and select system call is a blocking system call.

00:59.780 --> 01:00.530
Right?

01:00.770 --> 01:07.550
So when the server boots up, it gets blocked immediately at a select system call after creating a master

01:07.550 --> 01:08.840
socket file descriptor.

01:09.560 --> 01:15.890
Now, at this point of time, if any client C sends a connection request to the server.

01:18.530 --> 01:26.510
Then the server gets unblocked from the select system call and immediately calls an accept system call.

01:27.110 --> 01:35.960
The Accept System call creates a communication file descriptor using which the server communicates with

01:35.960 --> 01:39.200
the client for the rest of the lifetime of the connection.

01:41.490 --> 01:49.110
So as soon as the communication file descriptor is created using accept system call, the server makes

01:49.110 --> 01:51.270
a call to the receive from system call.

01:51.270 --> 01:56.430
That is, the server waits for the data from the client.

01:57.090 --> 02:02.970
So the server gets blocked at the stage three.

02:04.170 --> 02:09.010
That is, the server is waiting for the data from the client.

02:09.030 --> 02:11.220
So let us call this client as C1.

02:11.910 --> 02:16.620
Now at this point of time, that is when the server is in stage three.

02:16.800 --> 02:22.710
Suppose there is another client, C2, which again sends a connection request to the server.

02:24.200 --> 02:32.510
Now because the server is blocked in the stage three The server do not entertain the connection request

02:32.510 --> 02:34.100
from the client see to.

02:35.820 --> 02:36.420
Right.

02:36.420 --> 02:43.470
So this was the drawback in our TCP client and server design that we had just discussed because the

02:43.470 --> 02:47.540
server is waiting for the data from the client.

02:47.560 --> 02:51.660
C1 That is, the server is blocked at the stage three.

02:51.690 --> 02:56.220
The server s cannot entertain any other client.

02:57.290 --> 02:58.010
Right.

02:58.160 --> 03:00.470
So because of this.

03:01.100 --> 03:08.570
This TCP server had a drawback that it can entertain only one client at a time.

03:09.880 --> 03:10.600
Right.

03:10.900 --> 03:15.160
So when the client C1 sends the data to the server.

03:15.520 --> 03:22.690
Now, note that it is not a connection request, but it is a data, so the server moves from the stage

03:22.690 --> 03:24.580
three to the stage four.

03:26.010 --> 03:35.280
Right and at the stage for the server can process the client data and reply back to the client even

03:36.090 --> 03:37.970
after replying back to the client.

03:38.130 --> 03:41.880
Even the server again moves back to the stage three.

03:43.140 --> 03:48.180
So you can see that the server is oscillating between the stage three and four.

03:49.960 --> 03:56.800
And while the server is oscillating between the stages three and four, the server is entertaining only

03:56.800 --> 03:58.030
the client C1.

03:58.840 --> 04:06.340
So the type of design that we had just discussed is a design in which the server can entertain only

04:06.340 --> 04:08.170
one client at a time.

04:09.180 --> 04:17.520
Right because the server can entertain another another client only when the server is blocked at the

04:17.520 --> 04:18.810
select system call.

04:19.260 --> 04:27.180
But in this design, once the server receives the connection request from the client C1 the server Unblocks

04:27.180 --> 04:34.500
from the select system call and get stuck between the stage three and four forever.

04:35.490 --> 04:36.150
Right.

04:36.150 --> 04:43.020
So this is the reason that in this design the server cannot entertain more than one client.

04:45.210 --> 04:45.690
Right.

04:45.690 --> 04:49.890
So you must be thinking then what is the use case of such a design?

04:50.400 --> 04:54.840
So it's not like that that this design is useless.

04:54.840 --> 05:03.960
This design is still useful in the scenario where there is only one client to be served by the server.

05:04.560 --> 05:12.810
So this kind of design is used where there is only one and only one dedicated client of a server.

05:12.840 --> 05:19.920
Such server processes are used in system softwares where there is only one client and one server.

05:21.090 --> 05:27.360
This server design cannot handle multiple clients connections that we have discussed.

05:27.390 --> 05:35.220
So remember, servers are just another process which accepts some data from another process.

05:35.220 --> 05:37.800
So nothing is special, right?

05:37.830 --> 05:44.100
Servers are just another processes which can accept the data from another processes which are called

05:44.200 --> 05:48.880
clients and can process that data and return back the result.

05:49.600 --> 05:57.130
So such a machine which accepts the data, process the data and return the result are usually called

05:57.430 --> 06:00.340
are usually termed as server machines.

06:01.060 --> 06:03.910
Server doesn't generate any data.

06:03.940 --> 06:08.080
That means server doesn't generate any data by itself.

06:08.110 --> 06:14.530
Server has the property that they just replies to the client after processing the client's data.

06:14.680 --> 06:21.620
Server by themselves never sends message to the client without client's initiation first.

06:21.640 --> 06:24.880
So this is the basic property of the server.

06:25.450 --> 06:30.970
So now we have discussed how to write a TCP server which can entertain only one client.

06:31.000 --> 06:37.540
Let us now discuss how to write a TCP client program.

06:38.080 --> 06:45.280
So writing a TCP client is fairly easy as compared to writing a TCP server, right?

06:45.400 --> 06:52.390
And after that we will going to discuss the design of a TCP server in which the server can actually

06:52.420 --> 06:55.420
handle multiple clients at the same time.
