WEBVTT

00:05.070 --> 00:10.620
So let me show you the demonstration of client and server program so you can see the two windows on

00:10.620 --> 00:15.390
the screen on the left hand side that is in the left window.

00:15.420 --> 00:21.900
I will execute the server process and on the right window I will execute the client process.

00:22.320 --> 00:28.560
So you can see in this directory we have two files server and client dot C, So we will compile these

00:28.560 --> 00:35.640
two files and we will create executable of the server and client process and we will execute each of

00:35.640 --> 00:36.120
them.

00:36.330 --> 00:39.060
So let us compile the server dot c file.

00:39.900 --> 00:44.640
So GCC minus g server dot c minus O server.

00:45.060 --> 00:49.200
So this is the command that you should use to compile your server program.

00:49.350 --> 00:52.230
So it has created a server executable.

00:52.230 --> 01:01.380
You can simply execute this file that is executable so you can see that your server has started and

01:01.380 --> 01:07.740
the first thing the server does is to create master socket file descriptor and the server has successfully

01:07.740 --> 01:13.560
invoked the bind system call and now your server is now waiting on the Accept system call.

01:14.370 --> 01:20.400
So remember the Accept system call is a blocking system call and therefore the execution do not proceed

01:20.430 --> 01:26.220
beyond accept system call until the server receives the connection initiation request from a client.

01:26.250 --> 01:31.890
So at this point of time our server process is actually blocked on accept system call.

01:32.340 --> 01:40.020
Now, on the right hand side, I will compile the client program and I will execute the client program

01:40.020 --> 01:42.210
on the right window.

01:43.710 --> 01:45.990
So compile the client program

01:49.680 --> 01:57.330
so it will create a client executable and now simply execute the client executable.

01:57.330 --> 02:04.200
So when you execute the client program, you can see that the something happens on the server side.

02:04.800 --> 02:12.940
So the moment you execute the client program, the client has created a socket file descriptor, the

02:12.940 --> 02:17.320
client created the communication file descriptor that is data socket.

02:17.380 --> 02:24.160
And the second thing that the client immediately does is to send the connection initiation request to

02:24.160 --> 02:30.910
the server using correct system call so you can see that our server has actually accepted the connection

02:30.910 --> 02:36.820
from the client and now the server is actually waiting for the actual data from the client.

02:37.330 --> 02:38.050
That is.

02:38.050 --> 02:44.860
Now our server has moved to data exchange or data communication phase with the client.

02:44.860 --> 02:50.920
And on the right hand side you can see that the client is now asking the user to send an integer number

02:50.920 --> 02:51.850
to the server.

02:52.660 --> 02:54.460
So let us send one.

02:55.390 --> 03:03.280
You can see on the left hand side that our server process has actually accepted the value one that is

03:03.280 --> 03:06.100
sent by the client and.

03:06.730 --> 03:10.150
It is now waiting for the next data item from the client.

03:12.160 --> 03:16.540
So the client will send two, three, four and let's say five.

03:17.350 --> 03:22.720
So you can see that all these values that is sent by the client is now.

03:23.670 --> 03:30.300
Has now been accepted by the server and the server internally has computed the summation of all these

03:30.300 --> 03:37.440
values, but the server will send back the result to the client only when the client sends zero to the

03:37.440 --> 03:38.100
server.

03:38.550 --> 03:42.150
So let us enter the value zero and see what happens.

03:42.300 --> 03:48.900
So we can see that our client has received the summation of the values that it has sent to the server.

03:49.680 --> 03:56.940
And also the thing to note here is that our client process has now terminated because after receiving

03:56.940 --> 04:02.730
the result from the server, we actually close the connection in the client program.

04:05.730 --> 04:12.060
Whereas on the server side you can see that a server after receiving the value zero from the client

04:12.060 --> 04:14.940
has actually sent the final result.

04:14.940 --> 04:19.290
That is the final summation of all the values it had received from the client.

04:19.650 --> 04:25.920
And after sending back the result to the client or server process, actually closed the connection with

04:25.920 --> 04:27.270
that particular client.

04:27.570 --> 04:36.720
And after that, as we discussed, our server process goes back to the outer infinite loop.

04:37.430 --> 04:43.730
And it get blocked itself on the accept system call that is it is now waiting for the new connection

04:43.730 --> 04:49.580
initiation request from the new client and is now ready to repeat the entire cycle again with the new

04:49.580 --> 04:55.910
client so we can execute the client executable again and again.

04:55.910 --> 05:02.030
You can see that the server that the server has now accepted the connection with this new client again

05:02.030 --> 05:09.380
and it is now again waiting for the integer values from the client and the same process repeats.

05:10.900 --> 05:16.810
And now if I enter zero, you can see that our client process has again received the result.

05:18.050 --> 05:19.580
So this goes on.

05:21.230 --> 05:21.800
Right.

05:21.800 --> 05:27.080
So our client server program is working fine as expected.

05:27.650 --> 05:31.250
But there is one flaw in this client server communication.

05:31.550 --> 05:38.630
And that flaw is that our server process can actually entertain only one client at a time.

05:40.970 --> 05:46.850
To demonstrate this drawback, let us say that we have started the client, right?

05:46.850 --> 05:50.720
And now this client is sending its data items to the server.

05:52.770 --> 05:53.520
Right.

05:53.520 --> 06:00.570
So our separate process at this point of time is now waiting or blocked on the read system call that

06:00.570 --> 06:03.930
is, it is waiting for the next data item from the client.

06:05.340 --> 06:13.650
Now, in the next window on the client side, if I start a new client, that is you can execute a same

06:13.650 --> 06:16.380
client executable in the separate window.

06:16.470 --> 06:24.060
It is as good as some new client has come up and it also wants to get connected with the same server.

06:24.330 --> 06:25.230
So.

06:25.230 --> 06:34.770
So executing the client executable in different windows on your machine is as good as like multiple

06:34.770 --> 06:37.620
clients wants to communicate with the same server.

06:38.250 --> 06:46.470
So you can see that the moment I execute the new client, you can see that our server process has not

06:46.470 --> 06:48.720
responded to this new client.

06:49.590 --> 06:58.240
And if the new client send its data items to the server and after that, if it sends zero, you can

06:58.240 --> 06:59.170
see that.

07:00.450 --> 07:03.150
It has not received any result from the server.

07:03.850 --> 07:08.230
In fact, the server process has not responded to this new client at all.

07:08.800 --> 07:15.910
The reason is that our server process has to be blocked on the accept system call in order to establish

07:15.910 --> 07:17.560
the connection with the new client.

07:17.710 --> 07:23.980
But at this point of time our server process is not blocked on accept system call, but it is blocked

07:23.980 --> 07:25.360
on the read system call.

07:25.720 --> 07:32.170
So our server process is actually waiting for the data item from the first client.

07:32.950 --> 07:43.600
So as long as our server is in a data exchange or data communication state with the first client, any

07:43.600 --> 07:48.760
other client in the system cannot participate in communication with the server.

07:49.690 --> 07:56.860
In a nutshell or in brief, our server process is actually able to handle only one client at a time.

07:57.280 --> 08:00.670
It cannot handle multiple clients at the same time.

08:01.860 --> 08:04.350
So this is the drawback of this server design.

08:04.350 --> 08:11.220
And in our next discussion of client server socket programming, we will try to improve the design of

08:11.220 --> 08:17.130
the server such that our server process will be able to handle multiple clients at the same time.

08:17.790 --> 08:19.740
So you should download this source code.

08:19.740 --> 08:26.310
As I have already mentioned, the path and how to download the source code, compile and execute these

08:26.310 --> 08:29.910
files on your machine and try to analyze what is going on.

08:30.600 --> 08:33.240
And please do not copy paste my code.

08:33.240 --> 08:35.490
Write your own codes from scratch.

08:35.820 --> 08:40.110
It will give you a fair confidence and build your knowledge thoroughly.

08:40.110 --> 08:45.300
If you write each and every line of code by yourself instead of copy pasting my code.

08:46.810 --> 08:48.950
So see you in the next section.

08:48.970 --> 08:49.870
Thank you.
