With port numbers assigned to UDP sockets, we can now precisely describe
UDP multiplexing/demultiplexing. Suppose a process in Host A, with UDP port
19157, wants to send a chunk of application data to a process with UDP port 46428
in Host B. The transport layer in Host A creates a transport-layer segment that
includes the application data, the source port number (19157), the destination port
number (46428), and two other values (which will be discussed later, but are unimportant for the current discussion). The transport layer then passes the resulting segment to the network layer. The network layer encapsulates the segment in an IP
datagram and makes a best-effort attempt to deliver the segment to the receiving host.
If the segment arrives at the receiving Host B, the transport layer at the receiving
host examines the destination port number in the segment (46428) and delivers the
segment to its socket identified by port 46428. Note that Host B could be running
multiple processes, each with its own UDP socket and associated port number. As
UDP segments arrive from the network, Host B directs (demultiplexes) each segment
to the appropriate socket by examining the segment’s destination port number.