03. Transport layer: Multiplexing and Demultiplexing
Transport Layer? It provides communication services directly to application processes running on different hosts. In this section, we’ll…
03. Transport layer: Multiplexing and Demultiplexing
Transport Layer? It provides communication services directly to application processes running on different hosts. In this section, we’ll look at the transport layer’s basic services: multiplexing and demultiplexing.
What is the transport layer?
The transport layer provides logical communication between application processes running on different hosts.
Logical communication means that, from an application’s perspective, the hosts appear to be directly connected — even though, in reality, the hosts may be far apart.
With this logical communication, application processes can exchange messages (packets) without needing to worry about the underlying physical infrastructure.
The services a transport-layer protocol can provide may be constrained by the service model of the underlying network-layer protocol. For example, if the network layer cannot guarantee delay or bandwidth for segment delivery, then the transport layer also cannot guarantee delay or bandwidth for application messages delivered between processes.
However, the transport layer can also compensate for limitations of the network layer. Even if the network-layer protocol is unreliable — meaning it may lose, corrupt, or duplicate packets — the transport layer can still provide reliable data transfer to applications.
Transport-layer protocols (UDP and TCP)
The Internet provides two transport-layer protocols to the application layer. When developing a network application, the developer must choose one of them when creating a socket
- UDP: provides an unreliable and connectionless service.
- TCP: provides a reliable and connection-oriented service.
*A transport-layer packet is called a segment (this is the common term in Internet RFC).
- UDP packets are also often called datagrams, but note that the term datagram is also used for network-layer packets, which can be confusing.
Multiplexing and Demultiplexing
Transport-layer functions that extend host-to-host delivery (IP) into process-to-process delivery.
A process can have one or more sockets, which act like “doors” for sending and receiving data over the network. Each socket has a unique identifier that depends on whether it is TCP or UDP.
Demultiplexing is the task of delivering the data carried in an incoming transport-layer segment to the correct socket. Multiplexing is the task, at the sending host, of collecting data chunks from multiple sockets, adding a transport-layer header (containing information needed later for demultiplexing), forming segments, and passing those segments down to the network layer.
Demultiplexing (Inbound)
From the network layer to the transport layer: Network layer → Transport layer → (segment delivery) → Socket → Application process
Multiplexing (Outbound)
From the transport layer to the network layer: Application process → Socket → Transport layer → (segment creation) → Network layer
Information needed for multiplexing
- Sockets with unique identifiers
- Special fields in each segment that indicate the destination socket: source port number and destination port number
- Each port number is a 16-bit value, ranging from 0 to 65535.
- 0–1023 are well-known ports (reserved; not freely usable).
- They are listed in RFC 1700.
- When developing an application, the developer must assign a port number for the application to use.
Concrete demultiplexing process (how UDP basically works)
- Assign a port number to each socket of a host process.
- When a segment arrives at the host, the transport layer checks the destination port number.
- The segment is delivered to the socket that corresponds to that port number.
- The segment’s data passes through the socket into the attached process.
UDP (connectionless) multiplexing/demultiplexing
Language: Python
- A UDP socket is created with:
clientSocket = socket(AF_INET, SOCK_DGRAM)In this case, a port number is automatically assigned. - A UDP socket is identified by: (destination IP address, destination port number)
- Why do we need the source port number and source IP address? They act as a return address — the receiver may need to send a segment back to the sender.
Example (client–server communication):
- The client sends a request message to the server.
- The server receives the request message.
- The server sends the requested data back to the client. In step 3, the server uses the client’s source address/port from the request as the destination address/port for the reply.
TCP (connection-oriented) multiplexing/demultiplexing
Language: Python
- A TCP socket can be created like this:
clientSocket = socket(AF_INET, SOCK_STREAM)clientSocket.connect((serverName, 12000)) - A TCP socket is identified by a four-tuple: (source IP address, source port number, destination IP address, destination port number)
Linux note
Open ports can be checked using the nmap command.
메타데이터
- post_id
- b31efdccd1ac
- slug
- 03-transport-layer-multiplexing-and-demultiplexing-b31efdccd1ac
- url
- https://medium.com/@white-onne/03-transport-layer-multiplexing-and-demultiplexing-b31efdccd1ac
- canonical_url
- https://medium.com/@white-onne/03-transport-layer-multiplexing-and-demultiplexing-b31efdccd1ac
- author_url
- https://medium.com/@white-onne
- status
- ok
- fetched_at
- 2026-07-14 03:07:18