WEBVTT

00:05.460 --> 00:06.860
Welcome back, guys.

00:06.870 --> 00:11.400
So next, we will going to discuss a new design of a TCP server.

00:11.880 --> 00:16.500
And that design is called a TCP server with multiplexing.

00:16.770 --> 00:20.880
So such a TCP server is called multiplexed TCP server.

00:21.270 --> 00:28.560
So in the previous TCP server design, we discussed the limitation of the TCP server that a TCP server

00:28.590 --> 00:35.880
cannot entertain any other client as long as it is not finished with the current client it is communicating

00:35.880 --> 00:36.540
with.

00:36.720 --> 00:37.410
Right.

00:37.410 --> 00:42.360
But servers are not supposed to entertain only one client at a time.

00:42.360 --> 00:49.380
The usual property of the server is that that it should be able to entertain multiple clients at the

00:49.380 --> 00:50.400
same time.

00:51.810 --> 00:59.910
So therefore it is important to understand the implementation of TCP server with multiplexing that is,

00:59.910 --> 01:07.240
servers which could entertain and which could carry out communication with multiple clients at the same

01:07.240 --> 01:07.870
time.

01:08.200 --> 01:13.300
So you can see there are ten steps to implement the Dhcp server with multiplexing.

01:13.300 --> 01:20.560
If we compare these ten steps with the ten steps of the TCP server that we implemented and discussed

01:20.560 --> 01:28.570
previously, you can find that these ten steps are exactly same as those ten steps that we discussed,

01:28.870 --> 01:29.650
right?

01:30.940 --> 01:38.830
So we will see in what respect the multiplexed Dhcp server implementation is different from the previous

01:39.160 --> 01:41.320
TCP server implementation.

01:42.400 --> 01:48.760
So let me discuss the high level idea regarding implementing a TCP server with multiplexing.

01:48.760 --> 01:53.170
So you have a server, say S, and suppose you have a client.

01:53.170 --> 02:01.030
C1 Initially when the server boots up, it maintains only one file descriptor and that file descriptor

02:01.030 --> 02:03.220
is called master socket file descriptor.

02:03.220 --> 02:03.760
Right.

02:03.760 --> 02:07.240
We have discussed this master socket file descriptor enough now.

02:07.240 --> 02:12.640
So master socket file descriptor is used to detect new client connection requests.

02:12.670 --> 02:13.270
Right?

02:13.270 --> 02:19.750
So our TCP server is actually monitoring only the master socket file descriptor in the select system

02:19.750 --> 02:20.230
call.

02:20.260 --> 02:27.040
Now suppose the client C1 sends the connection initiation request to the server s, then the server

02:27.040 --> 02:34.000
s creates a new communication file descriptor using which it can carry out communication with the client.

02:34.030 --> 02:40.480
C1 So at this point of time the server s is maintaining two file descriptors the master socket file

02:40.480 --> 02:45.910
descriptor and the communication file descriptor of client C1 Right.

02:45.910 --> 02:54.880
Now suppose at some point of time that is later client C2 comes and it sends connection initiation request

02:54.880 --> 03:04.540
to the server s so server s will create a communication file descriptor for the client C2 and it will

03:04.540 --> 03:06.400
carry out communication with the client.

03:06.400 --> 03:09.190
C2 using that communication file descriptor.

03:09.940 --> 03:16.660
So you can see that every time a new client gets connected to the server, the server creates a communication

03:16.660 --> 03:22.540
file descriptor and keeps an array of those communication file descriptors.

03:24.010 --> 03:24.580
Right.

03:24.580 --> 03:31.900
So our server is able to carry out communication with multiple connected clients at the same time because

03:31.930 --> 03:37.690
our server is keeping track of the communication file descriptor of all the connected clients.

03:38.320 --> 03:43.510
So this data structure could be as simple as an array, right?

03:43.510 --> 03:49.600
So every time a new client gets connected to our TCP server, our server will create the communication

03:49.750 --> 03:57.100
file descriptor of that particular client and add that communication file descriptor in the array.

03:57.800 --> 03:58.520
Right.

04:00.900 --> 04:09.360
And every time a select system call is called by the TCP server, it will copy this entire array into

04:09.360 --> 04:11.160
read set.

04:13.370 --> 04:14.870
It will copy.

04:14.870 --> 04:20.180
And remember, the select system call is used to monitor all the file descriptors which are present

04:20.180 --> 04:21.590
in read set.

04:22.040 --> 04:22.700
Right.

04:22.700 --> 04:29.480
So using select system call or TCP server is actually monitoring all the file descriptors of all the

04:29.480 --> 04:30.800
connected clients.

04:32.700 --> 04:33.150
Right.

04:33.150 --> 04:39.330
And this is how our TCP server will be able to do multiplexing with multiple clients.

04:41.330 --> 04:48.410
So I am just describing you a high level design that how TCP server with multiplexing capability can

04:48.410 --> 04:50.360
be implemented in C.

04:52.240 --> 04:58.930
When we will have a code walk, you will have a clear idea that how this particular idea is implemented

04:58.930 --> 05:01.210
in network programming.

05:05.650 --> 05:12.040
Also note that suppose the client c to terminate its connection with the server s then what will server

05:12.070 --> 05:12.880
s will do?

05:12.910 --> 05:18.700
It will simply delete the communication file descriptor for the client C2 from the array.

05:19.900 --> 05:21.400
It will delete.

05:22.000 --> 05:22.690
Right.

05:22.690 --> 05:29.530
So in the read set, when this array will be copied in the read set, only the communication file descriptor

05:29.530 --> 05:31.750
of connected clients will be present.

05:32.110 --> 05:32.800
Right.

05:32.800 --> 05:38.560
So it means that the server s will not be communicating with the client C2 anymore.

05:39.250 --> 05:47.920
So let us discuss the code walk of TCP server with multiplexing and see how it differs from the previous

05:47.920 --> 05:50.230
TCP server that we discussed.

05:52.010 --> 05:59.120
So by now you have a fair idea that how TCP server with multiplexing capabilities actually works.
