TCP & UDP
| Done |
|---|
- Provides transparent transfer of data between end hosts
- Provide (or not provide) various services to applications:
- Reliable data transfer
- error recovery
- data sequencing
- Flow control
- Layer 4 Addressing (port numbers)
- Identifies the service the application is trying to access
- Provides multiplexing between sessions
💡
Session: exchange of data between two or more communicating devices
💡
IMPORTANT: The Destination Port identifies the Application Layer Protocol
💡
IMPORTANT: The reply reverses the Source and Destination ports of the request. This makes the requester able to identify which session a segment belongs to.
| Type | Range | Description |
|---|---|---|
| Well-known | 0 - 1023 | Highly regulated ports, used by major protocols |
| Registered | 1024 - 49151 | Less regulated, but still need registration with IANA (Internet Assignment Numbers Authority) |
| Ephemeral/private/dynamic | 49152 - 65535 | These are the ports used randomly to populate the source ports |
TCP (Transmission Control Protocol)
- Connection-oriented → Connection must be first established in order to exchange data
- TCP 3-Way Handshake
- Provides reliable communication → Segments must issue a acknowledgment that they received that segment
- Provides sequencing → Destination host knows how to put segments in the correct order with they arrived out of so.
- Flow Control → The destination host can tell the source to increase/decrease the rate that the data is transferred.
Important fields in the TCP Header
- The Source Port and the Destination Port fields have 16 bits (2 bytes) each of size → 2^16 = 65536 ports (0 - 65535)
- Sequence Number and Acknowledgment number → Provide sequencing and reliable communication
- Flags:
- ACK (Acknowledgment)
- SYN (Synchronization)
- FIN
- Window Size → Flow Control
Three-Way Handshake (Initiate connection)

Four-Way Handshake (Terminate Connection)

Sequence Number and Acknowledgment number

💡
REMEMBER: The Sequence number, except the SYN and the SYN/ACK ones, is ALWAYS equal to the Acknowledgment number of the previous segment (Forward acknowledgment = indicates the sequence number of the next number it expects to receive).
The Acknowledgment number is ALWAYS one number greater than the sequence of the previous segment.
UDP (User Datagram Protocol)
Although it also has error-detection (NOT error-recovery), it doesn`t have any of the features that TCP has. However, since it is less complex and doesn`t rely on acknowledgment, it has a greater performance, usually crucial for real-time applications.
Comparing TCP vs UDP
| TCP | UDP |
|---|---|
| Connection-oriented (3-Way Handshake) | Connectionless |
| Reliable | Non-Reliable |
| Sequencing | NO sequencing |
| Flow Control | NO Flow Control |
| High overhead | Low overhead |
| File transfer, downloads, etc. | VoIP, live video, etc. |
Major Port Numbers
| TCP | UDP | TCP & UDP |
|---|---|---|
| FTP data (20) | DHCP server (67) | DNS (53) |
| FTP control (21) | DHCP client (68) | |
| SSH (22) | TFTP (69) | |
| Telnet (23) | SNMP agent (161) | |
| SMTP (25) | SNMP manager (162) | |
| HTTP (80) | Syslog (514) | |
| POP3 (110) | ||
| HTTPS (443) |