1. 6
TCP/IP & UDP
Computer Networks (CSI-504)
Prepared By: Ghayour Abbas
Outline:
• TCP/IP
• UDP
TCP
Transmission Control Protocol (TCP) widely known as Internet Protocol (IP) is a
set of communications protocols used over the internet for delivery of services or
packets within or across the network. It is commonly known as internet protocol
suite.
The TCP/IP protocol consists of four layers such as link layer, network layer,
transport layer, and application layer.
Each layer adds addresses to the protocol stack as a physical address, logical
address, port address, and application-specific address.
2. TCP is a connection-oriented point-to-point transport communication
protocol that sends data packets as an unstructured stream of bytes in an ordered
sequence. TCP provides information from sending node about the delivery of
packets transmitted to a destination node by using sequence numbers and
acknowledgment messages. TCP ensures reliability, end-to-end delivery,
resequencing and retransmitting of data until a timeout condition is reached or
acknowledgment of data packets is received.
TCP offers flow control mechanism to sustain high transmission of packets
over a speeding network as well as TCP protocols offer error detection and lost
data features by trigging retransmission of data packets until an error-free
acknowledgment is received. The TCP/IP protocol maintains communication with
application layer protocols such as (FTP) file transfer protocol, (SMTP) simple
mail transfer protocol, and (HTTP) hypertext transfer protocol.
UDP
User Datagram Protocol (UDP) is a connectionless transport layer
communication protocol used to establish low tolerating and loss latency
connections for delivery of services or packets within or across the network.
It is coupled with an internet protocol suite as an alternative to TCP/IP
protocol. UDP constructs a datagram packet and addresses it with a port number
of IP appended with data packets and optional checksum capability to verify
receipt of intact data arrival. Since UDP protocol is simple protocol, the
retransmissions of packets can be decided at sender’s end whether to trade low
latency for high reliability over data transmission. UDP reduces overall network
traffic owing to network broadcasts feature which broadcasts packets to some
computers on the same network and eliminates the need for duplication across
the network. As UDP is connectionless protocol, the delivery or order of the data
content packets varies.
UDP conjunctions with higher level protocols such as trivial file transfer
protocol, real-time streaming protocol, simple network protocol, and domain
name system lookups to manage data transmission services across the network.
3. TCP Vs. UDP
Data Transfer Features
TCP enables the establishment of a strong connection between two hosts to
exchange data in streams. TCP guarantees to deliver data in the same ordered
manner as sent from server to user and vice versa. Thus, TCP is a connection-
oriented protocol. However, UDP is connectionless and non-dedicated protocol
does not check the readiness of the receiver host.
Reliability
Reliability of TCP is comparatively higher as it ensures message acknowledgment
and retransmissions of data in case of loss of data parts in transit. Hence, the
hosts do not lose any missing data. On the other hand, UDP does not offer
concepts of message acknowledgments, time-out or retransmission feature.
Therefore, there is no communication of whether the packets have reached
receiver or lost in transit.
Sequence
TCP transmits data packets in the same sequence as received. In case data
packets are arriving in the wrong order, TCP reorders them and delivers in the
correct order. In case of UDP, messages sent in a particular sequence may or may
not be maintained while delivering the host. Therefore, the sequence or order in
which packets will be transmitted is unpredictable.
Connection
A TCP connection is heavyweight, and it requires almost three packets for an
appropriate socket connection and handles the congestion control and reliable
delivery. UDP connection, on the other hand, is lightweight and transports layers
designed over a particular IP. No connections are tracking or ordering of
messages.
Data Streaming
Transmission Control Protocol reads data as streams of bytes, and the message is
transmitted to segment boundaries. UDP messages contain packets that were
sent one by one and are checked for integrity at the time of arrival.
4. Transfer Speed
The speed of TCP is slower as compared to UDP as it checks for errors and
retransmits the packets.
Header Size
TCP’s size of the header is 20 bytes, whereas, UDP is 8 bytes. However, they have
common header fields that are, source point, destination point, and checksum.
5. 8 bits equal 1 byte.
TCP headers appear in the following sequence, beginning with the source
and destination communication endpoints:
• Source TCP port number (2 bytes or 16 bits): The source TCP port
number represents the sending device.
• Destination TCP port number (2 bytes or 16 bits): The destination
TCP port number is the communication endpoint for the receiving
device.
• Sequence number (4 bytes or 32 bits): Message senders use
sequence numbers to mark the ordering of a group of messages.
• Acknowledgment number (4 bytes or 32 bits): Both senders and
receivers use the acknowledgment numbers field to communicate
the sequence numbers of messages that are either recently received
or expected to be sent.
• TCP data offset (4 bits): The data offset field stores the total size of a
TCP header in multiples of four bytes. A header not using the
optional TCP field has a data offset of 5 (representing 20 bytes), while
a header using the maximum-sized optional field has a data offset of
15 (representing 60 bytes).
6. • Reserved data (3 bits): Reserved data in TCP headers always has a
value of zero. This field aligns the total header size as a multiple of
four bytes, which is important for the efficiency of computer data
processing.
• Control flags (up to 9 bits): TCP uses a set of six standard and three
extended control flags—each an individual bit representing On or
Off—to manage data flow in specific situations.
• Window size (2 bytes or 16 bits): TCP senders use a number,
called window size, to regulate how much data they send to a
receiver before requiring an acknowledgment in return. If the
window size is too small, network data transfer is unnecessarily slow.
If the window size is too large, the network link may become
saturated, or the receiver may not be able to process incoming data
quickly enough, resulting in slow performance. Windowing
algorithms built into the protocol dynamically calculate size values
and use this field of TCP headers to coordinate changes between
senders and receivers.
• TCP checksum (2 bytes or 16 bits): The checksum value inside a TCP
header is generated by the protocol sender as a mathematical
technique to help the receiver detect messages that are corrupted or
tampered with.
• Urgent pointer (2 bytes or 16 bits): The urgent pointer field is often
set to zero and ignored, but in conjunction with one of the control
flags, it can be used as a data offset to mark a subset of a message as
requiring priority processing.
• TCP optional data (0 to 40 bytes): Usages of optional TCP data
include support for special acknowledgment and window scaling
algorithms.
UDP Header Format
Because UDP is limited in capability compared to TCP, its headers are
smaller. A UDP header contains 8 bytes, divided into the following four
required fields:
7. • Source UDP port number (2 bytes): The source UDP port number
represents the sending device.
• Destination UDP port number (2 bytes): The destination UDP port
number is the communication endpoint for the receiving device.
• Length of data (2 bytes): The length field in UDP represents the total
size of each datagram, including both header and data. This field
ranges in value from a minimum of 8 bytes—the required header
size—to sizes above 65,000 bytes.
• UDP checksum (2 bytes): Similar to TCP, a UDP checksum allows
receivers to cross-check incoming data for any corrupted bits of the
message.
Usage by Other Protocols
Use by other protocols FTP, SMTP, HTTP, HTTPs, Telnet use TCP Protocols, and
UDP protocols are used by TFTP, SNMP, DNS, DHCP, RIP, VOIP.
Detection of Errors
Transmission Control Protocol detects errors via checksum and performs error
recovery. If any of the packets are erroneous, they do not get acknowledged by
the receiver, which in turn triggers re-transmission by host/sender.
This mechanism is known as PAR (Positive Acknowledgement with
Retransmission). Since TCP is slower than UDP, TCP is appropriate for applications
that do not require high speed or longer period took for transmission is not a
constraint.
Regarding error detection and error recovery, UDP works on a best effort basis.
This protocol also supports error detection. However, the erroneous packets
detected by checksum are discarded. UDP does not attempt to retransmit
packets.
The reason UDP does not attempt retransmission of packets is that this protocol is
commonly used for time-sensitive applications such as voice transmission,
gaming, etc. Hence, recovery attempt would be of no point as by the time
retransmission takes place, and the packets are received, they will be of no use.