Multiplexing happens at the sender:
Demultiplexing happens at the receiver:
Demultiplexing
Host receives IP datagrams
Datagrams have source IP address + destination IP address
Each datagram carries one transport-layer segment - segment has source and destination port number
Host uses IP addresses & port numbers to direct segment to the appropriate socket
Connectionless Demultiplexing
On creation of a UDP socket, a host-local port number must be specified - this is included in transport layer.
UDP sockets on destination are uniquely specified by pair of (destination IP address, destination port number).
On host receipt of UDP segment, the host checks the destination port number in the segment and directs the UDP segment to the socket with the matching port number.
Note in this example, the messages from different hosts have their messages written to the same receiver.
Connection-Oriented Demultiplexing
TCP sockets are uniquely identified by the 4-tuple of: