TCP/IP Transport Layer
Purpose
- Ensuring **process-to-process delivery **of the entire message between **applications **on different hosts
Protocols
User Datagram Protocol (UDP)
- Connectionless, unreliable and lightweight transport-layer protocol
- Simple protocol using minimum overhead
- Speed is more important than reliability
Characteristics
- **Connectionless **– No handshake before communication starts
- **Unreliable **– No guarantee of delivery or order
- Fast and efficient – It has a minimal 8 byte header
Protocol Transmission Unit

- UDP packets, called user datagrams, have a fixed-size header of 8 bytes

- Checksum includes 3 section: Pseudoheader + UDP header + Data
- Pseudoheader is part of the IP packet header
Applications
- Real-time applications (fast , low latency).
- VoIP (Voice over IP)
- Online gaming
- Streaming media
- Lightweight services
- Domain Name System (DNS), :53
- Dynamic Host Configuration Protocol (DHCP), :67 (server) or :68 (client)
- Trivial File Transfer Protocol (TFTP), :69
- Broadcast/Multicast
- Routing Information Protocol (RIP), :520
- Multicast DNS (mDNS), :5353
Transmission Control Protocol (TCP)
- Connection-oriented protocol that provides reliable, ordered, and error-checked delivery of data between applications over a network
Characteristics
- Connection-oriented – Before any data can be transmitted, a reliable connection must be obtained and acknowledged
- Reliable Delivery – Ensures data integrity (no loss or corruption) with acknowledgements and timeouts
- Error Checking – Use checksum to detect error
- Flow Control – Prevent overwhelming of the receiver
- **Congestion Control **– Manage traffic load to avoid congestion
- Ordered Delivery – Reassembled in correct order with sequence number
Protocol Transmission Unit


- TCP packets are also called called segments, which are sent as a stream of bytes
- Each byte in this stream has a number

Mechanisms for Reliable Transmission
Acknowledgements
- Receiver sends an ACK with the next expected byte number
- It confirms that data was received correctly and in order
- Shows that each side of the communication has its own sequence numbers for the data it wants to transfer
- Sender sends the acknowledgement number that is the sequence number of the last byte received from receiver plus one
- Receiver sends acknowledgement number that is the sequence number of the last byte received from sender plus one
Retransmission

- Sender retransmits the data if it does not receive an ACK within a time
- TCP sets a retransmission timer for each sent segment
- This ensures that lost ACKs or segments are detected and re-sent
- TCP has mechanism that allows faster recovery from packet loss by allowing sender to retransmit after receiving three duplicate ACK
Checksum
- Each TCP segment includes a 16-bit checksum covering the header and data
- It detects corruption during transmission
- If a segment is corrupted (invalid checksum), the segment is discarded by the destination TCP and is considered as lost
- TCP checksum calculation follows the same procedure as UDP
- It includes 3 section: Pseudoheader + TCP header + Data
- Pseudoheader is part of the IP packet header
Flow Control (Sliding Window)

- Receiver advertises window size → controls how much data sender can transmit, prevents buffer overflow
- Sliding window vs simple ACK → allows multiple packets in flight (better efficiency than stop-and-wait)
- Operates at octet (byte) level, not packet/segment level
- Window size is dynamic:
- Increases when receiver frees buffer space
- Decreases when the buffer fills up
- Can be zero to pause the sender completely
- Each ACK includes updated window size, telling sender how many more bytes can be sent
Ordered delivery

- Receiver stores out-of-order segments and waits to deliver in sequence
- Each segment, from a large group of segments composing the user data, is assigned a sequence number
- This number represents the sequence number of the first byte of user data carried in this particular segment
Connection Establishment (3 Step Handshake)

- TCP uses a three-way handshake process
- Three messages are exchanged that allow each side to agree to form a connection and know that the other side has agreed
- SYN: Synchronise (Client → Server)
- SYN + ACK: Synchronise + Acknowledgment (Server → Client)
- ACK: Acknowledgment (Client → Server)
- Initial sequence number (ISN) is used for synchronisation
- Client chooses a random number as the first sequence number
Connection Termination (4 Step Teardown)

- TCP uses a four-way handshake process
- Three messages are exchanged that allow each side to agree to form a connection and know that the other side has agreed
- FIN: Finish (Client → Server)
- ACK: Acknowledgement, then send leftover data (Server → Client)
- FIN: Finish (Server → Client)
- ACK: Acknowledgment (Client → Server)
- Initial sequence number (ISN) is used for synchronisation
- Client chooses a random number as the first sequence number
Port Numbers

| Name | Purpose |
|---|
| Well-Known / System Ports | The ports ranging from 0 to 1023 are assigned and controlled by IANA |
| Registered / User Ports | The ports ranging from 1024 to 49151 are not assigned or controlled by IANA |
| Dynamic / Private Ports | The ports ranging from 49152 to 65535 are neither controlled nor registered, which can be used as temporary or private port numbers |
Addresses

Sockets
Definition

- A socket is an endpoint of communication between 2 devices on a network
- It is an interface between the application layer and transport layer
- It is located between the operating system and application programs
- To access the services provided by the TCP/IP protocol suite, an application needs to use the instructions defined in the socket interface
- Socket Address consists of a combination of IP address and port number
Types of Sockets

Stream Socket (TCP)
- Connection-oriented, reliable, ordered, error-checked delivery
Datagram Socket (UDP)
- Fast, unreliable, connectionless communication