1 4TCP
1 4TCP
APPLICATIONS
Class: I MCA Batch: 2023-2025
Course code:23CAR08 Course Title: DATA
COMMUNICATION AND
NETWORKS
1.TCP Services
Process-to-Process Communication
TCP provides process-to-process communication using port numbers. Table 4.2 lists
some well-known port numbers used by TCP.
TCP is a stream-oriented protocol. TCP allows the sending process to deliver data as
a stream of bytes and allows the receiving process to obtain data as a stream of
bytes.
TCP creates an environment in which the two processes seem to be connected by
an imaginary "tube" that carries their data across the Internet.
This imaginary environment is depicted in Figure 4.13. The sending process
produces (writes to) the stream of bytes, and the receiving process consumes (reads
from) them.
Because the sending and the receiving processes may not write or read data
at the same speed, TCP needs buffers for storage.
There are two buffers, the sending buffer and the receiving buffer, one for
each direction.
One way to implement a buffer is to use a circular array of I-byte locations as
shown in Figure 4.14. For simplicity, we have shown two buffers of 20 bytes
each; normally the buffers are hundreds or thousands of bytes, depending on
the implementation.
We also show the buffers as the same size, which is not always the case.
Figure 4.14 shows the movement of the data in one direction. At the sending site, the
buffer has three types of chambers.
The white section contains empty chambers that can be filled by the sending process
(producer). The gray area holds bytes that have been sent but not yet acknowledged.
TCP keeps these bytes in the buffer until it receives an acknowledgment. The colored
area contains bytes to be sent by the sending TCP.
Segments
Segments although buffering handles the disparity between the speed of the
producing and consuming processes, we need one more step before we can
send data.
The IP layer, as a service provider for TCP, needs to send data in packets,
notas a stream of bytes.
At the transport layer, TCP groups a number of bytes together into a packet
called a segment. Figure 4.15 show segments are created from the bytes in
the buffers.
3.Full-Duplex Communication
TCP offers full-duplex service, in which data can flow in both directions at the same time. Each
TCP then has a sending and receiving buffer, and segments move in both directions.
4.Connection-Oriented Service
TCP is a connection-oriented protocol. When a process at site A wants to send and receive
data from another process at site B, the following occurs:
Reliable Service
TCP is a reliable transport protocol. It uses an acknowledgment mechanism to check the safe
and sound arrival of data.
5.TCP Features
TCP has several features.
Numbering System
Although the TCP software keeps track of the segments being transmitted or received, there is
no field for a segment number value in the segment header. Instead, there are two fields
called the sequence number and the acknowledgment number. These two fields refer to the
byte number and not the segment number.
Byte Number
TCP numbers all data bytes that are transmitted in a connection. Numbering is independent in
each direction. When TCP receives bytes of data from a process, it stores them in the sending
buffer and numbers them.
The bytes of data being transferred in each connection are numbered by TCP. The numbering
starts with a randomly generated number.
Sequence Number
After the bytes have been numbered, TCP assigns a sequence number to each segment that
is being sent. The sequence number for each segment is the number of the first byte carried in
that segment.
The value in the sequence number field of a segment defines the number of the first data byte
contained in that segment.
When a segment carries a combination of data and control information (piggybacking), it uses
a sequence number. If a segment does not carry user data, it does not logically define a
sequence number. The field is there, but the value is not valid. However, some segments,
when carrying only control information, need a sequence number to allow an acknowledgment
from the receiver. These segments are used for connection establishment, termination, or
abortion.
Acknowledgment Number
Communication in TCP is full duplex; when a connection is established, both parties can send
and receive data at the same time. Each party numbers the bytes, usually with a different
starting byte number.
The sequence number in each direction shows the number of the first byte carried by the
segment. Each party also uses an acknowledgment number to confirm the bytes it has
received. However, the acknowledgment number defines the number of the next byte that the
party expects to receive. In addition, the acknowledgment number is cumulative, which means
that the party takes the number of the last byte that it has received, safe and sound, adds I to
it, and announces this sum as the acknowledgment number.
6.Flow Control
TCP provides flow control. The receiver of the data controls the amount of data that are to be
sent by the sender. This is done to prevent the receiver from being overwhelmed with data.
The numbering system allows TCP to use a byte-oriented flow control.
Error Control
To provide reliable service, TCP implements an error control mechanism. Although error
control considers a segment as the unit of data for error detection (loss or corrupted
segments), error control is byte-oriented.
Congestion Control
TCP, unlike UDP, takes into account congestion in the network. The amount of data sent by a
sender is not only controlled by the receiver (flow control), but is also determined by the level
of congestion in the network.
7.Segment
8.Format
The segment consists of a 20- to 60-byte header, followed by data from the application
program. The header is 20 bytes if there are no options and up to 60 bytes if it contains
options.
• 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. This serves the same purpose as the source
port address in the UDP header.
• 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. This serves the same purpose as the
destination port address in the UDP header.
• Sequence number. This 32-bit field defines the number assigned to the first byte of data
contained in this segment. As we said before, TCP is a stream transport protocol. To ensure
connectivity, each byte to be transmitted is numbered. The sequence number tells the
destination which byte in this sequence comprises the first byte in the 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.
• 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 can be
between 5 (5 x 4 =20) and 15 (15 x 4 =60).
• Control. This field defines 6 different control bits or flags as shown in Figure 4.17.One or
more of these bits can be set at a These bits enable flow control, connection establishment
and termination, connection abortion, and the mode of data transfer in TCP. A brief description
of each bit is shown in Table 4.3 time.
Window size. This field defines the size of the window, in bytes, that the other party must maintain.
Note that the length of this field is 16 bits, which means that the maximum size of the window is
65,535 bytes. This value is normally referred to as the receiving window (rwnd) and is determined by
the receiver. The sender must obey the dictation of the receiver in this case.
Checksum. This 16-bit field contains the checksum. The inclusion of the checksum for TCP is
mandatory. For the TCP pseudo header, the value for the protocol field is 6.
Urgent pointer. This l6-bit field, which is valid, only if the urgent flag is set, is used when the
segment contains urgent data. It defines the number that must be added to the sequence number to
obtain the number of the last urgent byte in the data section of the segment.
Options. There can be up to 40 bytes of optional information in the TCP header.
a.Connection Establishment
TCP transmits data in full-duplex mode. When two TCPs in two machines are
connected,
they are able to send segments to each other simultaneously. This implies that each party must
initialize communication and get approval from the other party before any data are transferred.
Three-Way Handshaking:
The connection establishment in TCP is called three way handshaking. In our example, an
application program, called the client, wants to make a connection with another application program,
called the server, using TCP as the transport layer protocol.
The process starts with the server. The server program tells its TCP that it is ready to accept
a connection. This is called a request for a passive open. Although the server TCP is ready
to accept any connection from any machine in the world, it cannot make the connection
itself.
The client program issues a request for an active open. A client that wishes to connect to an
open server tells its TCP that it needs to be connected to that particular server. TCP can now
start the three-way handshaking process as shown in Figure 4.18.
To show the process, we use two time lines: one at each site. Each segment has values for
all its header fields and perhaps for some of its option fields, too. However, we show only the
few fields necessary to understand each phase. We show the sequence number, the
acknowledgment number, the control flags (only those that are set), and the window size, if
not empty. The three steps in this phase are as follows.
1. The client sends the first segment, a SYN segment, in which only the SYN flag is set. This
segment is for synchronization of sequence numbers. It consumes one sequence number.
When the data transfer start, the sequence number is incremented by 1. We can say that the
SYN segment carries no real data, but we can think of it as containing 1 imaginary byte.
A SYN segment cannot carry data, but it consumes one sequence number.
2. The server sends the second segment, a SYN +ACK segment, with 2 flag bits set: SYN and
ACK. This segment has a dual purpose. It is a SYN segment for communication in the other
direction and serves as the acknowledgment for the SYN segment. It consumes one
sequence number.
A SYN +ACK segment cannot carry data, but does consume one sequence number.
3. The client sends the third segment. This is just an ACK segment. It acknowledges the
receipt of the second segment with the ACK flag and acknowledgment number field. Note that
the sequence number in this segment is the same as the one in the SYN segment; the ACK
segment does not consume any sequence numbers.
An ACK segment, if carrying no data, consumes no sequence number.
Simultaneous Open
A rare situation, called a simultaneous open, may occur when both processes issue an active open.
In this case, both TCPs transmit a SYN + ACK segment to each other, and one single connection is
established between them.
The connection establishment procedure in TCP is susceptible to a serious security problem called
the SYN flooding attack. This happens when a malicious attacker sends a large number of SYN
segments to a server, pretending that each of them is corning from a different client by faking the
source IP addresses in the datagrams.
b.Data Transfer
After connection is established, bidirectional data transfer can take place. The client and
server can both send data and acknowledgments. The acknowledgment is piggybacked with
the data. Figure 4.19 shows an example.
In this example, after connection is established (not shown in the figure), the client sends
2000 bytes of data in two segments. The server then sends 2000 bytes in one segment.
The client sends one more segment. The first three segments carry both data and
acknowledgment, but the last segment carries only an acknowledgment because there are
no more data to be sent. Note the values of the sequence and acknowledgment numbers.
The data segments sent by the client have the PSH (push) flag set so that the server TCP
knows to deliver data to the server process as soon as they are received. The segment from
the server, on the other hand, does not set the push flag. Most TCP implementations have
the option to set or not set this flag.
Pushing Data
The sending TCP uses a buffer to store the stream of data coming from the sending
application program.
The sending TCP can select the segment size.
The receiving TCP also buffers the data when they arrive and delivers them to the
application program when the application program is ready or when it is convenient for the
receiving TCP.
This type of flexibility increases the efficiency of TCP.
However, on occasion the application program has no need for this flexibility