Skip to content

Transport Layer

The Transport layer provides end-to-end communication between applications running on different hosts. While the Internet layer handles routing packets across networks, the Transport layer ensures reliable or unreliable delivery of data to the correct application.

What is the Transport Layer?

The Transport layer sits on top of the Internet layer and provides communication services directly to applications. It's responsible for ensuring that data reaches the correct application on the destination host and handles issues like packet loss, duplication, and ordering. It does so by using port numbersPort numbers are 16-bit identifiers that distinguish between different applications or services running on the same host. They allow multiple applications to use the network simultaneously. to identify the correct application on the destination host. Basically, once the packet is on a machine via the IP/MAC address, port numbers are used to bifurcate the data to the correct application.

Key Functions:

  • End-to-End Communication: Connects applications on different hosts
  • Port Addressing: Identifies specific applications using port numbers
  • Reliability: Ensures data delivery (TCP) or provides best-effort delivery (UDP)
  • Flow Control: Manages data transmission rates
  • Error Detection: Identifies corrupted data

What are Port Numbers?

Port numbers are 16-bit identifiers that distinguish between different applications or services running on the same host. They allow multiple applications to use the network simultaneously.

Transport Protocols Overview

The Transport layer uses two main protocols to provide different types of communication services: UDP and TCP.

User Datagram Protocol (UDP)

UDP is a connectionless, unreliable transport protocol that doesn't guarantee delivery of data. It's a good fit for applications that require low latency and can tolerate some loss of data, such as video streaming, online gaming, and network discovery protocols.

It basically just sends the data to the destination host and doesn't care if it arrives or not and has no memory of the data it sent.

UDP Characteristics:

  • Connectionless: No connection establishment required
  • Unreliable: No delivery guarantees or retransmission
  • Simple: Minimal overhead and processing
  • Fast: No connection setup or acknowledgment delays
  • Stateless: No connection state maintained

Transmission Control Protocol (TCP)

TCP is a connection-oriented, reliable transport protocol that provides guaranteed delivery of data between applications. It establishes a virtual connection between sender and receiver before data transfer begins.

There are mechanisms set in place to ensure that the data arrives at the destination and any missing packets are retransmitted. It also ensures that the data arrives in the correct order.

TCP Characteristics:

  • Connection-Oriented: Establishes connection before data transfer
  • Reliable: Guarantees delivery and correct ordering
  • Flow Control: Prevents overwhelming receiver
  • Congestion Control: Adapts to network conditions
  • Full-Duplex: Bidirectional communication

TCP enables these features at the cost of higher latency and overhead.

TCP vs UDP Comparison

FeatureTCPUDP
ConnectionConnection-orientedConnectionless
ReliabilityGuaranteed deliveryBest-effort delivery
OrderingGuaranteed orderNo ordering
Flow ControlYesNo
Congestion ControlYesNo
Header Size20-60 bytes8 bytes
SpeedSlowerFaster
Use CasesWeb browsing, email, file transferVideo streaming, gaming, DNS

Questions

Q: Which protocol provides reliable, ordered data delivery?

TCP (Transmission Control Protocol) provides reliable, ordered data delivery with error checking and retransmission capabilities.

Q: What is the purpose of port numbers in the Transport layer?

Port numbers identify specific applications on a device. They ensure that data reaches the correct application when multiple applications are running on the same device.

Q: Which protocol is faster but less reliable?

UDP (User Datagram Protocol) is faster but less reliable than TCP. It provides connectionless delivery without guarantees of delivery or ordering.

Q: What is the range of well-known port numbers?

Well-known port numbers range from 0-1023. These ports are reserved for common services like HTTP (80), HTTPS (443), SSH (22), and FTP (21).

Q: What is the main difference between TCP and UDP?

TCP is connection-oriented, establishing a connection before data transfer, while UDP is connectionless, sending data immediately without connection setup.

Q: What is the purpose of sockets in network programming?

Sockets provide programming interfaces for network communication. They allow applications to send and receive data over the network using transport protocols like TCP and UDP.