So let me show you the demonstration of client and server program so you can see the two windows on
the screen on the left hand side that is in the left window.
I will execute the server process and on the right window I will execute the client process.
So you can see in this directory we have two files server and client dot C, So we will compile these
two files and we will create executable of the server and client process and we will execute each of
them.
So let us compile the server dot c file.
So GCC minus g server dot c minus O server.
So this is the command that you should use to compile your server program.
So it has created a server executable.
You can simply execute this file that is executable so you can see that your server has started and
the first thing the server does is to create master socket file descriptor and the server has successfully
invoked the bind system call and now your server is now waiting on the Accept system call.
So remember the Accept system call is a blocking system call and therefore the execution do not proceed
beyond accept system call until the server receives the connection initiation request from a client.
So at this point of time our server process is actually blocked on accept system call.
Now, on the right hand side, I will compile the client program and I will execute the client program
on the right window.
So compile the client program
so it will create a client executable and now simply execute the client executable.
So when you execute the client program, you can see that the something happens on the server side.
So the moment you execute the client program, the client has created a socket file descriptor, the
client created the communication file descriptor that is data socket.
And the second thing that the client immediately does is to send the connection initiation request to
the server using correct system call so you can see that our server has actually accepted the connection
from the client and now the server is actually waiting for the actual data from the client.
That is.
Now our server has moved to data exchange or data communication phase with the client.
And on the right hand side you can see that the client is now asking the user to send an integer number
to the server.
So let us send one.
You can see on the left hand side that our server process has actually accepted the value one that is
sent by the client and.
It is now waiting for the next data item from the client.
So the client will send two, three, four and let's say five.
So you can see that all these values that is sent by the client is now.
Has now been accepted by the server and the server internally has computed the summation of all these
values, but the server will send back the result to the client only when the client sends zero to the
server.
So let us enter the value zero and see what happens.
So we can see that our client has received the summation of the values that it has sent to the server.
And also the thing to note here is that our client process has now terminated because after receiving
the result from the server, we actually close the connection in the client program.
Whereas on the server side you can see that a server after receiving the value zero from the client
has actually sent the final result.
That is the final summation of all the values it had received from the client.
And after sending back the result to the client or server process, actually closed the connection with
that particular client.
And after that, as we discussed, our server process goes back to the outer infinite loop.
And it get blocked itself on the accept system call that is it is now waiting for the new connection
initiation request from the new client and is now ready to repeat the entire cycle again with the new
client so we can execute the client executable again and again.
You can see that the server that the server has now accepted the connection with this new client again
and it is now again waiting for the integer values from the client and the same process repeats.
And now if I enter zero, you can see that our client process has again received the result.
So this goes on.
Right.
So our client server program is working fine as expected.
But there is one flaw in this client server communication.
And that flaw is that our server process can actually entertain only one client at a time.
To demonstrate this drawback, let us say that we have started the client, right?
And now this client is sending its data items to the server.
Right.
So our separate process at this point of time is now waiting or blocked on the read system call that
is, it is waiting for the next data item from the client.
Now, in the next window on the client side, if I start a new client, that is you can execute a same
client executable in the separate window.
It is as good as some new client has come up and it also wants to get connected with the same server.
So.
So executing the client executable in different windows on your machine is as good as like multiple
clients wants to communicate with the same server.
So you can see that the moment I execute the new client, you can see that our server process has not
responded to this new client.
And if the new client send its data items to the server and after that, if it sends zero, you can
see that.
It has not received any result from the server.
In fact, the server process has not responded to this new client at all.
The reason is that our server process has to be blocked on the accept system call in order to establish
the connection with the new client.
But at this point of time our server process is not blocked on accept system call, but it is blocked
on the read system call.
So our server process is actually waiting for the data item from the first client.
So as long as our server is in a data exchange or data communication state with the first client, any
other client in the system cannot participate in communication with the server.
In a nutshell or in brief, our server process is actually able to handle only one client at a time.
It cannot handle multiple clients at the same time.
So this is the drawback of this server design.
And in our next discussion of client server socket programming, we will try to improve the design of
the server such that our server process will be able to handle multiple clients at the same time.
So you should download this source code.
As I have already mentioned, the path and how to download the source code, compile and execute these
files on your machine and try to analyze what is going on.
And please do not copy paste my code.
Write your own codes from scratch.
It will give you a fair confidence and build your knowledge thoroughly.
If you write each and every line of code by yourself instead of copy pasting my code.
So see you in the next section.
Thank you.