What Is a Socket Connection?
In networking, connecting to a socket is a little more complicated than plugging something in. The language of networking uses terms we commonly use for physical connections as references to logical connections. In computer hardware a “port” is a plug socket, but in communications it is an address. In networking a “socket” is associated with a “port,” but neither of these words refers to one of the connectors on a computer.
-
Sockets
-
Ports and sockets are concepts of the TCP/IP protocol stack. This group of protocols includes two “transport protocols” called the Transmission Control Protocol and the User Datagram Protocol. Addressing between computers uses the Internet Protocol's IP address, addressing between applications uses ports. A port is a combination of the transport protocol and a port number. A socket is the combination of IP address and port enabling an application to communicate with a specific application on a specific computer.
Networked Programming
-
When an application contacts another application on another computer it has to refer to an IP address and a port. A socket is the combination of the two and a program can communicate with several different computers on the same port at the same time. To make it clear, which message is intended for which computer/port combination, the program creates a socket, which has a unique ID. Once the socket has been created, the network program labels each message with the socket ID instead of the IP address and port.
-
Socket Types
-
A receiving application uses two types of sockets. When an application that might expect to receive messages from other computers starts up, it notifies the network operating system on the computer of its presence and the port number it expects to receive messages on. It does this by creating a socket on that port. It then waits. This state is called listening.
Connections
-
When an application receives a message on a UDP port, it sends an answer to that message down the same socket on which it received the message. This is called connectionless communication. When the program receives a message on a TCP port, it negotiates a session with the application requesting a connection. The receiving application creates a new socket on the same port and creates the session on the new socket, leaving the original socket available for any new requests that might come in while the existing session is in operation. An application can maintain several sockets on the same port at the same time.
-
References
- Photo Credit Ablestock.com/AbleStock.com/Getty Images