Learn something new every day
More Info... by email
An Internet socket is a term used to identify a point of connection that any computer software program can use to transmit data over the Internet. They aren't a physical construct, like an electrical wall socket, but instead are a computer software concept. With such a socket, any necessary data may travel back and forth from a program running on one computer to a program running on another; in many cases, this is to and from a client and server. The term is also used to refer to an application programming interface (API) that computer programmers can use to create such network aware applications capable of sending and receiving data over the Internet.
Sockets work at the upper layers of the Internet protocol (IP) stack, known as the transport layer, where data is passed from an application down to the network via the operating system. When an application on the computer wishes to send and receive data from a network connection, it asks the operating system to open an Internet socket. The socket is set up consisting of the protocol information, such as user datagram protocol (UDP) or transmission control protocol (TCP), as well as the sending and receiving addresses of both computers and the IP port number for the connection. It is also possible for an Internet socket to be created that bypasses the operating system and sends the raw packets without first letting the computer's operating system deal with the additional socket information.
As used commonly on an Internet server, the server software starts up and opens up a listening socket. As the server receives a request for data, it then creates a unique socket for the requesting client, which it then uses to transmit any requested data. These types of connections are also referred to as a session, since the socket is closed up by the server once the client is finished. In this way, the server can create any number of simultaneous sockets with other clients, each with their own unique identifier, and deliver data that is unique to each client.
As such, there are three general types of Internet socket. One such type is the datagram socket. These are a fast socket connection that require no additional communication to establish a dedicated connection before sending packets of data. For this reason, they are often referred to as connectionless sockets and use UDP as their transport protocol. They're something of a fire-and-forget method, in that there's no packet sequence checking or error correction.
The connection-oriented sockets, however, called a stream socket, go through a few additional steps to establish the communication link between the client and server. These use TCP, or another protocol known as stream control transmission protocol (SCTP), for transport. This type of Internet socket is more reliable and has means for dealing with errors such as missing packets.
One other unique type of Internet socket is used primarily for computer network routing. This type of socket skips the transport layer of the IP stack, instead passing the packet from the network straight to the application with the socket information still intact. Such raw sockets allow for a much faster delivery of packets to the application, since the computer's operating system doesn't get to have its way with the packets first. The Internet control message protocol (ICMP) uses such raw sockets when one computer simply wants to "ping" another.