An introduction to Sockets

A socket is a logical communication End-point.  It is a software interface that provides a means of communicating between two networking devices or between two processes running on the same device (Unix Sockets).

The most popular analogy i have come across for a socket and quote the same is to “look at a socket as a door of a house with the house being the process (from Computer Networking – a top down approach)“. The socket forms the interface between the application layer and the Transport Layer.

The below diagram from the book Computer Networking – a top down approach provides a good depiction of a socket. The below example is for communication between two devices over the internet.

FIG Courtesy: Computer-networking : A top down Approach

The developer of the process (The application in this case) can choose the transport layer protocol (TCP/UDP/UNIX domain) that he wishes to communicate to. In case of communication between two devices on the internet, the socket API allows  the developer choice of the particular IP address to connect to and the port on which the service connection is desired (connecting to a web-server in this case).

For e.g – different websites have their own IP addresses and the port that might be opened to communicate with those websites would be either port 80 – http port or port 443 – https port.

We will look at different socket communication methods and try and write programs that will allow a reader to get comfortable with sockets.

Reference:

Computer Networking – A top Down Approach Kurose, Ros

The Linux Programming Interface, Michael Kerrisk

Basic Socket Communication APIs Explained

Leave a Reply

Your email address will not be published. Required fields are marked *