/ˈsɑː.kɪt/

noun — “the doorway your data knocks on when it wants to leave the machine.”

Socket is an endpoint for sending or receiving data across a network, allowing programs to communicate with other programs either on the same machine or across different systems. In operating systems and networking, a Socket represents a structured interface between an application and the network stack, abstracting away the gritty details of packets, routing, and hardware.

A Socket is typically defined by an address (such as an IP address) and a port number, along with a transport protocol like TCP or UDP. When a program opens a Socket, it asks the operating system to allocate the necessary resources and bind them to this endpoint. From the application’s perspective, the Socket behaves like a file-like interface, often exposed as an I/O Stream that can be read from or written to sequentially.

In client–server models, servers listen on a Socket for incoming connections, while clients create their own Sockets to initiate communication. Once connected, data flows in both directions until one side closes the connection. This model powers everything from web servers and APIs to chat applications and database connections. Without the humble Socket, the internet would mostly be a very quiet place.

Sockets integrate closely with operating system primitives like File Descriptor, which is how processes keep track of open network connections. This uniform treatment allows network communication to be redirected, monitored, or multiplexed alongside files and other resources. In a Command Line Interface environment, tools can interact with Sockets using the same redirection and piping techniques used for files.

Performance and reliability hinge on proper Socket management. Blocking versus non-blocking modes, buffering behavior, and timeout handling all affect responsiveness and throughput. Misconfigured Sockets can lead to stalled connections, dropped data, or resource exhaustion. Monitoring open Sockets is a common practice in diagnosing network congestion or application bottlenecks.

Socket abstractions extend beyond basic networking. Unix domain Sockets allow fast, local communication between processes on the same machine without touching the network stack. These are widely used for inter-service coordination, logging daemons, and system services that need speed without exposure.

Conceptually, Socket is like installing a mailbox on your program: messages arrive, you send replies, and neither side needs to know how the postal system actually works.

Socket is like a walkie-talkie for software — press to talk, release to listen, and hope nobody’s talking over you.

See TCP, UDP, Network Protocol, Client–Server Model, Network Port.