So guys, before diving deep into the select and Accept system call, it is important that we discuss
the high level Linux socket based communication design.
So to start with, messages which are sent by the client to the server can be categorized into two types.
The first type of messages are called connection initiation request messages.
These messages are used by the client to request a server to establish a dedicated connection only after
the connection has been established.
Then only the client can send.
The second type of messages which are called service request messages.
So the second type of messages are service request message.
Client can send these type of messages to the server once the connection is fully established through
these messages.
Client request server to provide a service.
Right.
So there are two types of messages connection, initiation, request messages.
So when the client C wants to connect with the server s, the client has to send the message called
connection initiation request messages.
So these are first type of messages.
Using these messages, client actually requests the server for connection establishment.
Once the connection is fully established, then only the client can use the services of the server by
using second type of messages called service request messages.
So server identifies and processes both the types of messages very differently.
We will discuss this in the next slide.
So to sum up, there are two types of messages the connection initiation request messages which are
sent by the client to the server.
The client sends these messages using a connect system call.
So Connect is a Linux system call and it is used on the client side and it is used when the client wants
to initiate a connection with the server.
Server On the other hand, uses the accept system call to receive the connection initiation request
from the client and complete the connection.
So for this purpose, the Linux provides the accept system call, which is to be used on the server
side.
The other type of messages are the service request messages.
These messages are sent by the client using using APIs such as send message or send to the server.
Receives the service request messages from the client using receive message API or receive from API.
Right.
You will actually see all these system calls in action when we will be discussing the socket programming
in detail later in this module.
Now let us try to understand the life cycle of a client server communication.
Now, when the server boots up, the very first thing that the server does is to create a master socket.
This master socket is created using a Linux system called called socket.
Right.
So we have a server here and let us assume that this server has booted up.
That is, this server has started and the first thing that the server will do is to create a master
socket.
And this master socket is created using socket system call.
Now I'm using the word master.
Right.
So it means that this socket has some special privileges.
Now, let us try to understand how this socket is special and what are those privileges that this socket
has.
So let us suppose that we have a client C1 somewhere in the network.
Let C1 sends the connection initiation request message to the server.
That means the client C1 wants to connect to the server.
Now note that the connection initiation request message is received by the server on the master socket.
When the server receives the connection initiation request from the client with the help of master socket,
the server create a handle for the client.
So this is the handle which is which is created by the server for the client.
C1.
Now.
What is handle?
Handle is nothing, but it is an object that is created by the server.
And using this object, the server will carry out all the future communication with the client.
C1.
So in short, the handle is nothing, but it represents a connection of the server with the client.
C1.
Now let us suppose there is another client C two.
This also sends a new connection initiation request to the server.
The server hand over the new connection initiation request to the master socket.
Having received the new connection initiation request with the help of master socket, the server creates
another handle for client C two.
Right.
So you can see every time the server receives a new connection initiation request using master socket,
the server creates a new handle for the client.
So it is for this reason that m that is the master socket is the mother of all client handles that is
the master socket, gives birth to all the client handles.
So if there are two clients, C1 and C2, which are connected to the server, the server will have two
clients handles.
So the server has to maintain both the client handles at the same time because it is now carrying out
communication with the two clients at the same time.
Now at this point of time, both the client C1 and C2 have established the connection fully with the
server.
Now clients are in the position that they can send service request messages to the server.
So let us say that the client C2 has send the service request message to the server.
Now the operating system that is running on the server will hand over the service request message directly
to the client handle.
So the service request message that is coming from the client, C2 will be handed over to the handle
which is corresponding to the client C2 on the server.
And using this handle, the server will process the request of the client and send back the service
response to the client back using handle C2.
Right.
So you can see that the client handle on the server is being used to process the service request messages
coming from the client.
And after processing the message, the same handle is being used to send back the service response to
the same client.
So all the future communication with the connected client is done by the client handle, which was created
by the master socket on the server.
So going forward, once client handles are created for each client server, carries out communication
with the client using client handle only.
Note that Master socket is not involved in service request processing of the client messages.
Master sockets are not used for processing service.
Request messages from the client.
Server has to maintain the database of connected client handles.
As you can see, there are two clients which are connected to the server at the same time.
Therefore, the server has to maintain two client handles at the same time.
So if there are n number of clients, then the server has to maintain n number of client handles so
that the server can communicate with each of those clients independently.
And that is the master socket is only used to create new client handles.
Right.
You can see that the master socket is used to process only new connection.
Initiation requests from the client's master socket is not used for data exchange with already connected
clients.
Data exchange means the service request messages.
Now coming to the accept system call accept is the system call which is used on the server side to create
client handles.
So the accept system call is used by the server to create new client handles and the argument to the
accept system call is the master socket.
Right?
So in Linux terminology handles are called file descriptors, which are nothing but just integer numbers.
Right.
Client handles are called communication file descriptors because they are used for carrying out real
communication with the client.
That is data exchange, whereas M is called the master socket file descriptor.
So this socket that is M is a master in the sense that it is the mother of client handles.
So to take an example, the service request could be the two numbers which are sent by the client to
the server and the client is asking the server to add two numbers.
Right?
When the server receives this client message, the server can add up the two numbers and send the result.
Back to the client, that is.
It will send the summation of A and B back to the client.
That is called service response.
So this is how Linux maintains the client server communication.
So this entire picture depicts the life cycle of a client server communication on Linux.