There are two main uses for the term socket in computing. One is a standard term carried over from electronics and refers to a physical holder into which some sort of microchip can be placed and secured. The other is specific to computing and refers to a software structure that serves as an endpoint to send and receive data over the network. Their meanings are distinct enough that it should be relatively easy to determine which one is meant from the context in which it is used.
In a computer, many components are physically soldered onto a few circuit boards, such as the motherboard. In some cases, though, relevant components can vary between individual computers. For example, some computers have more RAM than others; not having this soldered onto the motherboard makes it easier to configure and even upgrade later. RAM, like most other components like this, has its own set of slots to connect to, physical connectors specifically designed to only be compatible with RAM.
The CPU, however, is a little different. Instead of being mounted so that its circuit board is perpendicular to the motherboard, it is parallel. This means that a standard slot won’t work. Instead, it needs to fit in a socket. The socket design is intrinsically related to the design of the CPU. The physical dimensions of the socket must match the CPU. The CPU makes electrical connections to the motherboard via several connector pins on the underside; the CPU socket must have the same number of connectors in the right places.
Note: Technically, the CPU socket also includes some form of retention mechanism and mounting points for a cooler. While this is standardized for socket generations, it theoretically could be arbitrarily changed. Many smaller sockets for standard microchips have integrated retention mechanisms.
In the early days of computers, before RAM came mounted on smaller circuit boards called DIMMs, individual RAM chips were also placed on the motherboard in sockets. You could also consider female electrical connectors, such as a USB port or a socket. In computing, female electrical connectors are generally referred to as ports. In electronics, however, they are often referred to as sockets, so both uses are correct.
One of the most valuable features of modern computers is the ability to communicate with other computers. This is done over networks and the Internet. To be able to communicate, a computer process needs to open a network socket. A network socket is generally identified by the IP address, the port number, and network protocol, i.e., TCP. On the software end, this information is represented as a unique ID known as a socket identifier.
A socket must be associated with a communication protocol, i.e., TCP, UDP, and IP. It also needs to be associated with a local address; this always includes an IP address and often includes port numbers, though raw IP doesn’t feature port numbers. Sockets connected to other sockets, i.e., after a TCP connection is established, are also linked to the remote IP address and port number.
When a socket is configured to listen over connection-oriented protocols like a server listening on a TCP port, the socket can be further identified by the IP and port of the remote host. This allows one configured local socket to listen to multiple connections at once. This relies on the service dedicating a thread to each active connection. Each received packet is handled in order. This doesn’t work with the “connectionless” UDP.
Sockets like this may even be used for non-network communication. For example, inter-process communication also uses sockets. While these essentially function the same, the actual linking is different as it doesn’t use networking protocols.
The term socket has two meanings. One refers to an electrically female connector with two large dimensions, i.e., distinct from a slot. Historically sockets were used to mount several microchips on motherboards. However, outside of development hardware, the only component that uses a socket in a modern computer is the CPU. Sockets can also refer to network sockets.
These are local identifiers. The software sees them as unique IDs though the operating system links them to a protocol, IP address, and port number. Given the difference between the hardware and the communication use cases, the two should be relatively easy to differentiate based on the context.