Network Sockets as a Foundation for Communication
Explore how network sockets enable communication between client and server processes by creating unique channels identified by IP addresses and ports. Understand the roles of stream and datagram sockets, how multiple concurrent connections operate, and how sockets underpin modern API development. This lesson equips you with insights into the fundamental network interactions essential for designing effective APIs and product architectures.
Introduction
APIs provide services by exchanging information between client and server processes. The underlying network stack usually abstracts this interprocess communication, but how is it done? Popular API technologies such as RESTful, GraphQL, and gRPC work differently, but at the most basic level, they all use socket interfaces for process identification, connection establishment, and interprocess communication.
Let’s see the basic requirements for successful communication between two processes or services that operate on separate networked devices:
Identification of devices on the internet.
Identification of processes on the communicating devices.
Steps or procedures to exchange data between those processes.
Let’s understand how sockets play an important role in maintaining these three requirements.
What is a socket?
A socket is an interface that creates a two-way channel between processes communicating on different devices. Processes running on the application layer use sockets as an interface to take services from the transport layer to establish communication. Further, the interfacing requires an IP address and a port number to uniquely identify a process or application globally. The interface (IP address + port) is referred to as a socket address.
Two different sockets (endpoints) are required for any two processes to communicate. Each process in a connection is recognized by its respective socket address. The diagram below shows how “Process A" from a machine with "IP 1" can communicate with the “Process X" on another machine with "IP 2."
Note: The ports used to run services on different devices can be different or the same. We can also assign the same port to different services on different devices connected to the internet. Port numbers ranging between 1–1024 are well-known ports because they’re mostly used as a standard for a particular service. For example, port 80 and 443 are used for HTTP and HTTPS, respectively.
Finally, the ...