Sockets: How a Program Gets a Way to Communicate
A socket is a communication endpoint that an operating system supplies to a program. The program uses it to send and receive data, whether the other end is across the internet or elsewhere on the same computer.
It's a software object, not the hole where a network cable plugs in. A browser, for example, can ask the operating system for a socket and then use it to communicate with a web server, the program supplying a website.
The operating system gives the program a way to refer to that socket. On Linux, that reference is a number called a file descriptor. Linux's socket documentation describes both the endpoint and the choices a program makes when creating one.
What Do Port Numbers Actually Do?
A stream or a series of messages?
A TCP socket provides a reliable, two-way stream of bytes. TCP stands for Transmission Control Protocol; a byte is a small unit of digital data. The program reads from and writes to that stream, while the protocol handles the rules for delivering the data in order.
A UDP socket handles separate messages, called datagrams. UDP stands for User Datagram Protocol. It doesn't provide the same promise of reliable delivery and order. A program using it has to account for those limits in the way it communicates.
So “uses sockets” isn't enough to tell you whether an application will receive every message or how it handles missing information. The socket type and the protocol behind it supply those details.
The address belongs to the endpoint
For internet TCP communication, a socket address combines an Internet Protocol (IP) address with a port number. The address identifies a network location. The port helps the computer sort incoming traffic among services and conversations.
An address describes where an endpoint can be reached; it isn't the entire socket object. Nor does one endpoint identify a complete TCP connection. That takes both ends, the socket pair.
Some sockets serve local communication between programs on the same machine. These use a different address system, so the familiar “IP address plus port” description doesn't apply to every socket.
A server can also have sockets doing different jobs. One listens for new connection requests. When a request is accepted, a separate connected socket handles that conversation while the original keeps listening. Linux's accept operation explicitly preserves the listener.
- Stop fearing the terminal: start from your first command and build from there.
- Automate boring tasks with shell scripts you write yourself.
- Understand what each command does instead of copying it blindly.
A connection still needs protection
Creating a socket gives a program a way to communicate. It doesn't by itself encrypt the conversation or decide what another program is allowed to request.
Transport Layer Security, or TLS, is a separate protocol that can protect communication over a reliable, ordered transport. It encrypts the content and provides authentication—evidence about the identity of the other endpoint. The TLS specification describes those protections.
The application still has its own decisions to make. A protected connection can deliver a request to open a private record; the software receiving it must decide whether that requester has permission. The socket carries the exchange. It doesn't write the access rules.
Network Ports: How Numbers Sort Traffic Between Programs

Socket Pair: The Two Ends of a Connection

What's a Client? The Software That Makes the Request

QUOTE:
"Amateurs hack systems, professionals hack people."
