Sockets in Operating System

in the previous lectures we have studied about message-passing systems and shared memory systems which were two strategies that were used for communication between processes so the message passing system and shared memory systems can also be used for communication in a client-server based system and in this lecture we’ll be studying about sockets which is also a strategy used for communication between processes and this is mainly used for client-server based systems so the sockets are a strategy that is used for communication.
In client-server systems now let us see what are these sockets how do they work and how do they help in communication between two or more processes so first of all let us see what is a socket or how can we define a socket a socket is defined as an end point for communication so how we can define socket is it is defined as an end point for communication so when two processes or two systems want to communicate with each other sockets are the end points on either end of the communicating processes so a pair of processes communicating over a network employ a pair of sockets one for each process.
So as I told you when two processes wants to communicate there needs to be a connection between them and at each end of the connection each of this processes will employ a socket each so a pair of communicating processes over a network will employ a pair of sockets one for each process now we will see how can we identify a socket a socket is identified by an IP address concatenated with a port number so a socket is identified by an IP address every socket will have an IP address concatenated with a port number that means it will be followed by a port number so it will have an IP address and following that it will have a port number so that is how sockets are identified so I will showing you examples of this as we move further but for now you remember that sockets are identified by an IP address followed by a port number.
Now let us see how does a communique between these processes employing a pair of sockets take place so what happens is the server waits for incoming client requests by listening to a specified port once a request is received the server accepts a connection from the client socket to complete the connection so first of all let us understand what is client and server you may already know in a client-server systems the client asks for information from the server and the server will give that information to the client that’s how it works so in order for the client to communicate to the server and the server to communicate back to the client there needs to be a connection between the client and the server so in order to establish this connection we are going to use the sockets and as I told you sockets are identified by an IP address along with a port number so what the server does is it waits for incoming client requests by listening to a specified port so each process will be associated with a socket and that socket will be having a port number now the server.
It listens to the port waiting for some incoming client requests and once a request is received that means once a client is trying to communicate to the server the server accepts the connection from the client socket to complete the connection so once the server receives the connection requests from the client what it does is it will accept that connection from the client socket to complete the connection so once a connection is established they can now communicate with each other and remember that at either ends at the servers and and add the clients ends with both the processes there are sockets and the sockets are the ones that will enable this connection to be established now moving forward servers implementing specific services such as telnet FTP and HTTP listen to well-known ports for example a telnet server listens to port 23 an FTP server listens to port 21 and a web or HTTP server listens to port number 80 so as I told you a socket is identified by an IP address followed by a port number so a port number is going to identify each of the processes or each of the services that are going to be provided now servers which implement specific services such as telnet FTP and HTTP these are specific services that are implemented by servers like for example telnet telnet is used for remote login then FTP stands for File Transfer Protocol which is used for transferring files and HTTP as we all know it is hypertext Transfer Protocol so these are certain services that are implemented by servers and these services they listen to specific ports there are specific port numbers that are reserved for these specific services so telnet it listens to port 23 FTP server listens to port 21 and the HTTP server listens to port 80 so these port numbers are reserved for these specific services and these port numbers cannot be assigned to some other client processors or any other processes so we should keep that in mind and it says here that all ports below one zero to four are considered well-known and we can use them to implement standard services so just like I showed you before like telnet listens to port 23 FTP 221 and HTTP 280 similarly all the port numbers below 1 0 to 4 are reserved for specific services alright so what we mean by this is whenever we want to assign a port number to the client process or any other processes as such we should not use port numbers below 1 0 to 4 because most of the numbers below 1 0 to 4 are reserved for standard services like the ones that I showed you before now moving on let us take a visual example and see how does communication using sockets takes place so here in this diagram I have this first part which is the host and I have the second part which is the web server think of this as the client and this as the server so the client wants to request something from the server and the server has to fulfill that request by giving whatever the client asked from the server so in order for that to occur we need to have a communication link between this server and the client there has to be some kind of link between the server and client so in order to establish this communication link we are going to use the concept of sockets which we have just studied so let’s see this is the socket that belongs to the client so when a client process initiates a request for connection it is assigned a port by the host computer.

Leave a Comment