NETWORKING / A CONCEPT NOTE

Ports & Sockets

how one machine runs many services

~60 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

A socket is the combination of an IP address and a port (e.g., 127.0.0.1:8080). Ports allow a single machine to multiplex traffic, routing packets to the correct application.

02 / FOLLOW THE MECHANISM

How socket connections flow

  1. App

    binds to a port (e.g., 80) and enters a LISTEN state.

  2. Client

    connects from a random high-numbered port (e.g., 51234) to server's port 80.

  3. OS

    creates a unique socket pair linking client IP:port to server IP:port.

  4. Communication

    packets flow between these specific sockets without mixing with other services.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

find what process is listening on port 8080

lsof -i :8080

EXAMPLE 02 · REFERENCE

list all active TCP and UDP listeners on the machine

ss -tulpn

Explore command anatomy in the CLI lab