What is a TCP socket?
11 March 2022 (Updated 11 March 2022)
A TCP socket is an endpoint for a single process on a host. This endpoint is identified by a combination of IP address and port number ( e.g., 172.1.167.13:5555
). This combination of IP address and port number is used in the TCP/IP suite (at the network and transport layer) to route data from a source process to the target process.

As an example, here’s how sockets are used in a HTTP request:
- John opens a tab in a web browser to navigate to
google.com
. The browser creates a new process for that tab and assigns the process a unique socket ( e.g.,11.111.11.111:5555
). This tab is now reachable at this socket. - The browser does some work to resolve the socket of the remote process listening at
google.com
( e.g.,22.222.22.222:80
) and issues a HTTP request. - During the data encapsulation stages of the TCP/IP protocols, the tab’s socket (
11.111.11.111:5555
) is included as part of the sending packet. - The TCP/IP suite uses the destination socket to route the request to the correct IP (
22.222.22.222
) and then to the correct port (80
). - The web server listening on port
80
receives the incoming request and does some work to prepare a response. - The web server adds some metadata to the response that includes the original client socket.
- The TCP/IP suite uses the destination socket (IP address and port number) to route the data to the original client process (browser tab).
- The browser renders the response.
List TCP socket pairs
Linux (might need to run sudo apt-get install net-tools
):
macOS:
Example output:
Tagged:
Networking
Thanks for your comment . Once it's approved, it will appear here.
Leave a comment