Layer 4 – how TCP and UDP ports work
Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are normally what is meant when we discuss Layer 4 communications, in particular how they use the concept of ports.
When a station wants to talk to another station in the same subnet using its IP address (the IP usually gets determined in the application or presentation layers), it will check its ARP cache to see whether there's a MAC address that matches that IP. If there's no entry for that IP address, it will send an ARP request to the local broadcast address (as we discussed in the last section).
The next step is for the protocol (TCP or UDP) to establish port-to-port communications. The station picks an available port, above 1024
and below 65535
(the maximum port value), called the ephemeral port. It then uses that port to connect to the fixed server port on the server. The combination of these ports, combined with the IP addresses at each end and the...