TCP Udp
TCP Udp
8.2
•Connection-oriented Requires a session connection (analogous to a phone
call) be established before any data can be sent. This method is often called a
"reliable" network service. It can guarantee that data will arrive in the same
order. Connection-oriented services set up virtual links between end systems
through a network.
8.3
8-2 USER DATAGRAM PROTOCOL (UDP)
8.4
Figure 8.9 User datagram format
8.5
Example 1 :The following is a dump of a UDP header in hexadecimal format.
CB84000D001C001C
8.6
Solution:
a. The source port number is the first four hexadecimal digits (CB84), which
means that the source port number is 52100.
b. The destination port number is the second four hexadecimal digits (000D),
which means that the destination port number is 13.
c. The third four hexadecimal digits (001C) define the length of the whole UDP
packet as 28 bytes.
d. The length of the data is the length of the whole packet minus the length of the
header, or 28 – 8 = 20 bytes.
8.7
Note
UDP length
= IP length – IP header’s length
8.8
8-3 TCP
8.9
Note
8.10
Example 2 :Suppose a TCP connection is transferring a file of 5,000 bytes. The first
byte is numbered 10,001. What are the sequence numbers for each segment if data are
sent in five segments, each carrying 1,000 bytes?
8.11
Note
8.12
Note
8.13
Figure 8.16 TCP segment format
8.14
Source port address. This is a 16-bit field that defines the port number of the
application program in the host that is sending the segment
Destination port address. This is a 16-bit field that defines the port number of the
application program in the host that is receiving the segment
Sequence number. This 32-bit field defines the number assigned to the first byte of data
contained in this segment
Acknowledgment number. This 32-bit field defines the byte number that the receiver
of the segment is expecting to receive from the other party. If the receiver of the segment
has successfully received byte number x from the other party, it returns x + 1 as the
acknowledgment number.
8.15
Header length. This 4-bit field indicates the number of 4-byte words in the TCP
header. The length of the header can be between 20 and 60 bytes. Therefore, the value
of this field is always between 5 (5* 4= 20) and 15 (15 * 4= 60).
Reserved. This is a 6-bit field reserved for future use.
Control. This field defines 6 different control bits or flags
Window size. This field defines the window size of the sending TCP in bytes. Note
that the length of this field is 16 bits, which means that the maximum size of the
window is 65,535 bytes.
Checksum. This 16-bit field contains the checksum
Urgent pointer. This 16-bit field, which is valid only if the urgent flag is set, is used
when the segment contains urgent data
8.16
Figure 8.18 Control field
8.17
Table 8.3 Description of flags in the control field
8.18
Flow Control
Flow control assists the reliability of TCP transmission by
adjusting the effective rate of data flow between the two services
in the session. Window Size field in the TCP header specifies the
amount of data that can be transmitted before an
acknowledgement must be received.
8.19
Figure 8.18 Connection establishment using three-way handshaking
8.20
A SYN segment cannot carry data, but it
consumes one sequence number.
A SYN + ACK segment cannot
carry data, but does consume one
sequence number.
8.21
Figure 8.19 Data transfer
8.22
Figure 8.20 Connection termination using three-way handshaking
8.23
The FIN segment consumes one
sequence number if it does
not carry data.
8.24
Figure 8.22 Sliding window
8.25
Note
8.26
Example 8.4
Solution
The value of rwnd = 5000 − 1000 = 4000. Host B can
receive only 4000 bytes of data before overflowing its
buffer. Host B advertises this value in its next segment
to A.
8.27
Example 8.5
Solution
The size of the window is the smaller of rwnd and cwnd,
which is 3000 bytes.
8.28
Note
Some points about TCP sliding windows:
❏ The size of the window is the lesser of rwnd and
cwnd.
❏ The source does not have to send a full window’s
worth of data.
❏ The window can be opened or closed by the
receiver, but should not be shrunk.
❏ The destination can send an acknowledgment at
any time as long as it does not result in a shrinking
window.
❏ The receiver can temporarily shut down the
window; the sender, however, can always send a
segment of 1 byte after the window is shut down.
8.29
Note
8.30
Figure 8.24 Normal operation
8.31
Figure 8.25 Lost segment
8.32
Note
8.33
Figure 8.26 Fast retransmission
8.34
TCP UDP
TCP is a connection-oriented
Connection UDP is a connectionless protocol.
protocol.
UDP has no inherent order as all
Ordering of TCP rearranges data packets in
packets are independent of each
data packets the order specified.
other.
Speed of The speed for TCP is slower UDP is faster because there is no
transfer than UDP. error-checking for packets.
There is absolute guarantee
that the data transferred There is no guarantee that the
Reliability remains intact and arrives in messages or packets sent would
the same order in which it was reach at all.
sent.
Header Size TCP header size is 20 bytes UDP Header size is 8 bytes.
8.35
TCP UDP
Streaming
Data is read as a byte stream, Packets are sent individually
of data
TCP does Flow Control. TCP
Data Flow UDP does not have an option for
requires three packets to set up a
Control flow control
socket connection,
Acknowle
Acknowledgement segments No Acknowledgment
dgement
8.36