Socket
In computer terms, a socket is an endpoint for communication between two programs on a network. It's a software construct, often a combination of an IP address and a port number, that allows applications to send and receive data across a network connection, similar to how a wall outlet allows an electrical device to connect to a power circuit.
Key characteristics of network sockets
Communication endpoint: A socket represents one end of a two-way communication link, and two programs must each have a socket to talk to each other.
Identifier: It is often represented by a unique combination of an IP address and a port number (e.g., \(192.168.1.1:8080\)).
Data stream: Data is exchanged as a stream of bytes written to the socket, with a pre-agreed-upon protocol defining how the data is interpreted.
Abstraction: A socket provides a programming interface that hides the complexities of the underlying network protocols, making it easier for applications to handle communication.
Types of sockets
Stream sockets (TCP): Provide a reliable, connection-oriented, full-duplex communication channel. They are used for applications like web browsing (HTTP) and secure shell (SSH) where data integrity is critical.
Datagram sockets (UDP): Provide a connectionless, faster, but less reliable method of communication. They are used for applications like live audio/video streaming, where speed is prioritized over guaranteed delivery.
Other meanings of "socket"
CPU socket: On a motherboard, this is the physical mechanical and electrical connector where the processor (CPU) is installed to connect it to the rest of the computer's hardware.