Operating System Concepts — Sockets

Tola Ore-Aruwaji
Level Up Coding
Published in
4 min readAug 6, 2020

--

Photo by Greg Rosenke on Unsplash

Sockets are strategies that are used for communication between processes. It is mainly used in client-server based systems. When two systems want to communicate with each other, sockets are the endpoint on either end of the communicating processes.

  • A pair of processes communicating over a network employs a pair of sockets-one for each process.

When two processes want 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.

How can we Identify a Socket?

  • A socket is identified by an IP address concatenated with a port number.
    Servers implementing specific services (such as TELNET, FTP, and HTTP) listen to well-known ports.
    For example,
  • TELNET server is used for remote logging which listens to port 23
  • FTP (File transfer protocol) is used for transferring files server listens to port 21
  • Web or Http (Hypertext transfer protocol) server listens to port 80
  • A port number is going to identify each of the processes, services that are going to be provided.

All ports below 1024 are considered well known; we can use them to implement standard services.

How does communication between these processes employing a pair of sockets take place?

  • 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.

In a Client-Server systems, the Client asks for information from the server and the Server provides the information to the client. 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.
In order to establish this connection, we are going to use sockets.

Communication using Sockets

From the diagram above, The first part is the Host and the second part is the Web server. The first part is the Client, the second part is the Server.

  • The Client wants to request something from the server, the Server has to fulfill the request by given whatever the Client asks from the Server. In other, for this to occur, there must be a communication link between the Server and the Client. The communication link is being established using the concept of Socket which we defined earlier.
  • From the first part of the diagram, a Client process is trying to establish a connection between the Client and the Server. The host computer will assign a port number to this process which wants to communicate with the server.
  • The IP address of the Host Computer from the diagram above is 146.86.5.20 a process that belongs to the Host computer wants to communicate with the Web Server. For that to be possible, a specific port number will be assigned by the Host computer to the Client process.
    The IP address is then assigned a port number 146.86.5.20:1625:1625 A port number is an arbitrary number greater than 1024. It is greater than 1024 because the port numbers below 1024 are considered well known and are used for implementing standard services.
  • Similarly in part B (The webserver) the Web server has a socket. the socket belongs to the process in the Web server that is going to communicate with the Client process. It has an IP address and port number 161.25.19.8:80

Port number 80 is less than 1024 because it’s the Web server and not the Client. The Client is trying to access some services from the Server, Port number 80 belongs to a standard service.

The packets that are traveling from the Client process to the Server process are delivered appropriately based on the port numbers

If another process from the Host computer wants to communicate to the same socket of the Web server, that process will again be assigned another socket. The socket number will be a new number different from 1625 and greater than 1024

Conclusion

This is how communication between systems/processes takes place using Sockets. This is another strategy that is used for communication between processes and this is very specifically used for the Client-Server system.

The Sockets are specifically used only for the Client-Server based systems.

  • You can also reach out to me on Twitter or find me on Github.

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

--

--