0% found this document useful (0 votes)
14 views9 pages

TCP vs UDP: Key Features and Differences

The document compares TCP and UDP protocols, highlighting TCP as reliable and connection-oriented, while UDP is faster but unreliable. It explains TCP's three-way handshake for establishing connections, the format of TCP segments, and congestion control mechanisms like slow start and congestion avoidance. Additionally, it discusses flow and error control in TCP, the differences between connection-oriented and connectionless services, TCP connection termination steps, and the role of the congestion window in managing data transmission.

Uploaded by

nazim4321raza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views9 pages

TCP vs UDP: Key Features and Differences

The document compares TCP and UDP protocols, highlighting TCP as reliable and connection-oriented, while UDP is faster but unreliable. It explains TCP's three-way handshake for establishing connections, the format of TCP segments, and congestion control mechanisms like slow start and congestion avoidance. Additionally, it discusses flow and error control in TCP, the differences between connection-oriented and connectionless services, TCP connection termination steps, and the role of the congestion window in managing data transmission.

Uploaded by

nazim4321raza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Compare and contrast TCP and UDP protocols


with respect to their features, reliability, and
applications. (Advantage and Disadvantage)
Definition
TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are two core
transport layer protocols in the TCP/IP suite. TCP is connection-oriented and reliable, while UDP
is connectionless and faster but unreliable.

Explanation
Feature TCP UDP

Connection-oriented (requires
Connection Connectionless (no handshake)
handshake)

Reliable (acknowledgments, Unreliable (no acknowledgments, no


Reliability
retransmissions) retransmit)

Ordering Guarantees in-order delivery No guarantee of order

Flow Control Yes (sliding window mechanism) No flow control

Only checksum (corrupted packets


Error Control Yes (checksum, retransmission)
discarded)

Congestion
Yes (slow start, congestion avoidance) No congestion control
Control

Speed Slower due to overhead Faster, minimal overhead

Header Size 20-60 bytes 8 bytes

Web (HTTP), Email (SMTP), File Transfer


Applications DNS, VoIP, Streaming, Online Games
(FTP)

Advantages and Disadvantages


TCP Advantages: Reliable, ordered, error-checked, suitable for applications needing data
integrity (e.g., file transfer).
TCP Disadvantages: Higher overhead, slower, not ideal for real-time or loss-tolerant
applications.
UDP Advantages: Low latency, minimal overhead, suitable for real-time and multicast
applications.
UDP Disadvantages: No reliability, no ordering, not suitable for critical data transfer.

Diagram Instruction
Draw this image: "Table or side-by-side diagram showing TCP (with handshake,
acknowledgments, window) and UDP (simple, no handshake, no ack)."

Memory Hack (Mnemonics)


"TCP = Total Care Protocol, UDP = Unreliable Data Push"
Word Count : 266

2. Explain the three-way handshake mechanism


for establishing a TCP connection.
Definition
The three-way handshake is a process used by TCP to establish a reliable connection between
a client and a server before data transfer begins.

Explanation
1. Step 1: SYN (Synchronize) Sent by Client
The client initiates the connection by sending a segment with the SYN flag set and an
initial sequence number (ISN) to the server.
2. Step 2: SYN-ACK Sent by Server
The server responds with a segment that has both SYN and ACK flags set. It
acknowledges the client's ISN and sends its own ISN.
3. Step 3: ACK Sent by Client
The client sends an ACK segment, acknowledging the server's ISN. The connection is
now established, and data transfer can begin.

Sequence Example
Client → Server: SYN, Seq = x
Server → Client: SYN-ACK, Seq = y, Ack = x+1
Client → Server: ACK, Seq = x+1, Ack = y+1

Importance
Ensures both sides are ready for communication.
Synchronizes sequence numbers for reliable data transfer.
Prevents old duplicate connections from causing confusion.
Diagram Instruction
Draw this image: "Timeline showing three segments: SYN (client to server), SYN-ACK (server to
client), ACK (client to server). Label sequence and acknowledgment numbers."

Memory Hack (Mnemonics)


"SYN, SYN-ACK, ACK = Say Hello, Reply, Confirm"
Word Count : 232

3. Draw and explain the TCP Segment format in


detail.
Definition
A TCP segment is the basic unit of data transmission in TCP, consisting of a header and data.
The header contains fields for addressing, sequencing, control, and error checking.

Explanation
1. Source Port (16 bits): Identifies the sending application.
2. Destination Port (16 bits): Identifies the receiving application.
3. Sequence Number (32 bits): Number of the first byte in this segment.
4. Acknowledgment Number (32 bits): Next expected byte from the other side.
5. Header Length (4 bits): Length of the TCP header.
6. Reserved (3 bits): Reserved for future use.
7. Control Flags (9 bits): URG, ACK, PSH, RST, SYN, FIN, etc.
8. Window Size (16 bits): Size of the receive window (flow control).
9. Checksum (16 bits): Error detection for header and data.
10. Urgent Pointer (16 bits): Indicates urgent data (if URG flag is set).
11. Options (variable): For additional features (e.g., MSS, SACK).
12. Data (variable): Actual payload from the application layer.

Example
A typical TCP segment for a web request will have source port 12345, destination port 80,
sequence and acknowledgment numbers, and control flags set as needed.
Diagram Instruction
Draw this image: "TCP segment format with labeled fields: Source Port, Destination Port,
Sequence Number, Acknowledgment Number, Header Length, Flags, Window, Checksum,
Urgent Pointer, Options, Data."

Memory Hack (Mnemonics)


"SDSHCFWUO" = Source, Destination, Seq, Header, Control, Flags, Window, Urgent,
Options
Word Count : 246

4. Explain congestion control mechanisms,


including slow start and congestion avoidance.
Definition
Congestion control refers to techniques used by TCP to prevent network congestion by
controlling the rate at which data is sent.

Explanation
1. Slow Start:
TCP starts with a small congestion window (cwnd), typically one segment. For each ACK
received, cwnd increases exponentially (doubles each round-trip time). This allows TCP
to probe the network capacity quickly.
When cwnd reaches a threshold (ssthresh), slow start ends.
2. Congestion Avoidance:
After reaching ssthresh, TCP increases cwnd linearly (by one segment per round-trip
time). This prevents overloading the network.
If packet loss is detected (timeout or triple duplicate ACKs), ssthresh is set to half of
cwnd, and cwnd is reduced (either to 1 or ssthresh).
3. Fast Retransmit and Fast Recovery:
On receiving three duplicate ACKs, TCP retransmits the lost segment immediately (fast
retransmit) and enters fast recovery, adjusting cwnd to avoid further congestion.

Importance
Prevents packet loss and delays due to congestion.
Ensures fair bandwidth sharing among users.
Adapts to changing network conditions.
Diagram Instruction
Draw this image: "Graph showing cwnd growth during slow start (exponential) and congestion
avoidance (linear), with ssthresh marked."

Memory Hack (Mnemonics)


"SSCA = Slow Start, Congestion Avoidance"
Word Count : 232

5. How does TCP ensure flow control and error


control? Explain with examples.
Definition
Flow control and error control are mechanisms in TCP to ensure reliable, orderly, and efficient
data transfer between sender and receiver.

Explanation
1. Flow Control (Sliding Window):
TCP uses a sliding window protocol, where the receiver advertises a window size (rwnd)
indicating how much data it can accept.
The sender can transmit only up to the window size without waiting for an
acknowledgment, preventing receiver buffer overflow.
Example: If rwnd = 5000 bytes, sender can send 5000 bytes before pausing for ACKs.
2. Error Control:
TCP uses sequence numbers and acknowledgments to detect lost or out-of-order
segments.
If a segment is lost or corrupted (detected by checksum), the receiver discards it and
the sender retransmits after a timeout or upon receiving duplicate ACKs.
Example: If segment 3 is lost, receiver sends duplicate ACKs for segment 2; sender
retransmits segment 3.
3. Cumulative and Selective Acknowledgments:
TCP normally uses cumulative ACKs, but some versions support selective ACKs (SACK)
for efficient recovery from multiple losses.

Diagram Instruction
Draw this image: "Sliding window with sender, receiver, window size, and ACKs. Show
retransmission on error."
Memory Hack (Mnemonics)
"FEC = Flow and Error Control"
Word Count : 236

6. What is a sliding window? How is it used in flow


control?
Definition
A sliding window is a flow control mechanism that allows a sender to transmit multiple frames
before needing an acknowledgment, based on the receiver's advertised window size.

Explanation
1. Working Principle:
The sender maintains a window of sequence numbers for frames it can send without
waiting for an ACK.
As ACKs are received, the window "slides" forward, allowing more frames to be sent.
The receiver also maintains a window for frames it can accept.
2. Flow Control:
The receiver advertises its buffer size (rwnd) to the sender.
The sender must not send more data than the window allows, preventing buffer
overflow at the receiver.
Example: If window size is 4, sender can send frames 1-4; after ACK for frame 1,
window slides to 2-5.
3. Advantages:
Increases throughput by allowing multiple frames in transit.
Reduces idle time and improves efficiency, especially in high-latency networks.

Diagram Instruction
Draw this image: "Sliding window diagram with sender, receiver, window size, and movement as
ACKs are received."

Memory Hack (Mnemonics)


"Window Slides as ACKs Arrive"
Word Count : 220
7. What are the differences between Connection-
Oriented and Connectionless services?
Definition
Connection-oriented and connectionless are two types of transport layer services that define
how data is transmitted between devices.

Explanation
Feature Connection-Oriented Service Connectionless Service

Setup Requires connection establishment (handshake) No setup required

Reliability Reliable (acknowledgments, retransmissions) Unreliable (no ACKs, no retransmit)

Ordering Guarantees in-order delivery No guarantee of order

Flow/Error Control Yes (window, error detection) No flow or error control

Overhead Higher (due to connection management) Lower (minimal protocol overhead)

Examples TCP, FTP, Telnet UDP, DNS, TFTP

Expanded Points
Connection-oriented is suitable for applications needing reliable, ordered delivery (e.g., file
transfer).
Connectionless is suitable for real-time or loss-tolerant applications (e.g., streaming, VoIP).

Diagram Instruction
Draw this image: "Two diagrams: one showing handshake and data flow (connection-oriented),
another showing direct data flow (connectionless)."

Memory Hack (Mnemonics)


"CO = Careful Order, CL = Carefree Loss"
Word Count : 220

8. Explain the steps involved in TCP connection


termination.
Definition
TCP connection termination is the process of gracefully closing an established TCP connection
using a sequence of control segments.
Explanation
1. Step 1: FIN Sent by Initiator
The client or server sends a segment with the FIN flag set, indicating it has finished
sending data.
2. Step 2: ACK Sent by Receiver
The receiver acknowledges the FIN by sending an ACK segment.
3. Step 3: FIN Sent by Receiver
The receiver, after sending all remaining data, sends its own FIN segment to indicate it
is done.
4. Step 4: ACK Sent by Initiator
The initiator sends a final ACK, confirming the connection is closed.

Half-Close Option
One side can close its sending direction while still receiving data (half-close), useful in some
applications.

Importance
Ensures all data is transmitted and acknowledged before closing.
Prevents data loss and ensures orderly release of resources.

Diagram Instruction
Draw this image: "Timeline showing FIN, ACK, FIN, ACK segments exchanged between client
and server."

Memory Hack (Mnemonics)


"FIN-ACK-FIN-ACK = Finish, Acknowledge, Finish, Acknowledge"
Word Count : 220

9. Define congestion window and its role in TCP


congestion control.
Definition
The congestion window (cwnd) is a TCP state variable that limits the amount of data a sender
can transmit into the network before receiving an acknowledgment, helping to prevent
congestion.
Explanation
1. Role in Congestion Control:
cwnd is dynamically adjusted based on network conditions. It starts small and grows as
ACKs are received, probing the network's capacity.
If packet loss is detected (timeout or duplicate ACKs), cwnd is reduced to control
congestion.
2. Interaction with Receiver Window (rwnd):
The actual window size for sending is the minimum of cwnd and rwnd, ensuring both
network and receiver are not overwhelmed.
3. Algorithms:
Slow Start: cwnd increases exponentially until a threshold (ssthresh) is reached.
Congestion Avoidance: cwnd increases linearly after ssthresh.
Fast Recovery: cwnd is adjusted quickly after detecting mild congestion.

Importance
Balances throughput and network stability.
Prevents congestion collapse by controlling data flow.

Diagram Instruction
Draw this image: "Graph showing cwnd growth and reduction during slow start, congestion
avoidance, and after packet loss."

Memory Hack (Mnemonics)


"cwnd = Congestion Window, Controls What’s Next Delivered"
Word Count : 220

1. [Link]

You might also like