Socket Addresses in TCP/IP

Transmission Control Protocol/Internet Protocol provides a set of 16-bit port numbers within each host.

Transmission Control Protocol/Internet Protocol (Transmission Control Protocol/Internet Protocol) provides a set of 16-bit port numbers within each host. Because each host assigns port numbers independently, it is possible for ports on different hosts to have the same port number. TCP/IP creates the socket address as an identifier that is unique throughout all Internet networks. TCP/IP concatenates the Internet address of the local host interface with the port number to devise the Internet socket address.

With TCP/IP, sockets are not tied to a destination address. Applications sending messages can specify a different destination address for each datagram, if necessary, or they can tie the socket to a specific destination address for the duration of the connection (see SOCK_DGRAM in Socket Types).

Because the Internet address is always unique to a particular host on a network, the socket address for a particular socket on a particular host is unique. Additionally, because each connection is fully specified by the pair of sockets it joins, every connection between Internet hosts is also uniquely identified.

The port numbers up to 255 are reserved for official Internet services. Port numbers in the range of 256-1023 are reserved for other well-known services that are common on Internet networks. When a client process needs one of these well-known services at a particular host, the client process sends a service request to the socket address for the well-known port at the host.

If a process on the host is listening at the well-known port, the server process either services the request using the well-known port or transfers the connection to another port that is temporarily assigned for the duration of the connection to the client. Using temporarily-assigned (or secondary) ports frees the well-known port and allows the host well-known port to handle additional requests concurrently.

The port numbers for well-known ports are listed in the /etc/services file. The port numbers above 1023 are generally used by processes that need a temporary port after an initial service request has been received. These port numbers are generated randomly and used on a first-come, first-served basis.