Chess Class
Chess Class
TCP 2
OSI Model Layer 4: Transport Layer
• It decides if data transmission should be on parallel path or single path.
• It receives messages from the Session layer above it, convert the message into
smaller units and passes it on to the Network layer.
• Transport layer breaks the message (data) into small units so that they are
handled more efficiently by the network layer.
Functions of Transport Layer
• Service Point Addressing: Transport Layer header includes service point address which is
port address. This layer gets the message to the correct process on the computer unlike
Network Layer, which gets each packet to the correct computer.
• Segmentation and Reassembling: A message is divided into segments; each segment
contains sequence number, which enables this layer in reassembling the message.
Message is reassembled correctly upon arrival at the destination and replaces packets
which were lost in transmission.
• Connection Control: It includes 2 types:
• Connectionless Transport Layer : Each segment is considered as an independent packet
and delivered to the transport layer at the destination machine.
• Connection Oriented Transport Layer : Before delivering packets, connection is made
with transport layer at the destination machine.
• Flow Control: In this layer, flow control is performed end to end.
• Error Control: Error Control is performed end to end in this layer to ensure that the
User Datagram Protocol (UDP)
• When sending packets using TCP/IP, the data portion of each IP packet is formatted
as a TCP segment.
• Each TCP segment contains a header and data.
• The TCP header contains many more fields than the UDP header and can range in
size from 202020 to 606060 bytes, depending on the size of the options field.
• A TCP segment consists of data bytes to be sent and a header that is added to the
data by TCP.
• The header of a TCP segment can range from 20 – 60 bytes.
• 40 bytes are options.
• If there are no options, a header is 20 bytes else it can be the utmost of 60 bytes.
Source port:
• It defines the port of the application, which is sending the data.
• So, this field contains the source port address, which is 16 bits.
Destination port:
• It defines the port of the application on the receiving side.
• So, this field contains the destination port address, which is 16 bits.
Sequence number:
• Sequence numbers are given to the segments to reassemble the bytes at the
receiver end, even if they arrive in a different order.
• Sequence number of a segment is the byte number of the first byte that is
being sent.
• It is 32 bit field.
• This field contains the sequence number of data bytes in a particular
session.
Acknowledgment number:
When the ACK flag is set, then this contains the next sequence number of the
data byte and works as an acknowledgment for the previous data received.
For example, if the receiver receives the segment number 'x', then it responds
'x+1' as an acknowledgment number.
HLEN:
• It specifies the length of the header indicated by the 4-byte words in the
header.
• The size of the header lies between 20 and 60 bytes. (4byte X 5 = 20 bytes)
• Therefore, the value of this field would lie between 5 and 15.
Reserved:
• It is a 4-bit field reserved for future use, and by default, all are set to zero.
There are six control bits or flags:
Among all the 6 control bits, only one can be set at a time.
• URG: It represents an urgent pointer. If it is set, then the data is
processed urgently.
• ACK: If the ACK is set to 0, then it means that the data packet
does not contain an acknowledgment.
• PSH: If this field is set, then it requests the receiving device to
push the data to the receiving application without buffering it.
• RST: If it is set, then it requests to restart a connection.
• SYN: It is used to establish a connection between the hosts.
• FIN: It is used to release a connection, and no further data
exchange will happen.
Window size
• It is a 16-bit field.
• It contains the size of data that the receiver can accept.
• This field is used for the flow control between the sender and receiver and also determines the amount
of buffer allocated by the receiver for a segment.
• The value of this field is determined by the receiver.
Checksum
• It is a 16-bit field.
• This field is optional in UDP, but in the case of TCP/IP, this field is mandatory.
Urgent pointer
• It is a pointer that points to the urgent data byte if the URG flag is set to 1.
• It defines a value that will be added to the sequence number to get the sequence number of the last
urgent byte.
Options
• It provides additional options.
• The optional field is represented in 32-bits.
• If this field contains the data less than 32-bit, then padding is required to obtain the remaining bits.
TCP Connection
• TCP is a connection-oriented protocol, which means that it first establishes the
connection between the sender and receiver in the form of a handshake.
• After both the connections are verified, it begins transmitting packets. It makes
the transmission process error-free and ensures the delivery of data.
• The transmitter is the server, and the receiver is known as the client.
• We can also say that the data transmission occurs between the server and client.
• TCP is used in most of the high-level protocols, such as FTP (File Transfer
Protocol), HTTP (Hyper Text Transfer Protocol), and SMTP (Simple Mail
Transfer Protocol).
• Handshake refers to the process to establish connection between the client and server.
• Handshake is simply defined as the process to establish a communication link.
• To transmit a packet, TCP needs a three way handshake before it starts sending data.
• The reliable communication in TCP is termed as PAR (Positive Acknowledgement Re-
transmission).
• When a sender sends the data to the receiver, it requires a positive acknowledgement
from the receiver confirming the arrival of data.
• If the acknowledgement has not reached the sender, it needs to resend that data.
• The positive acknowledgement from the receiver establishes a successful connection.
• A 3-way handshake is commonly known as SYN-SYN-ACK and requires both the client
and server response to exchange the data.
• SYN means synchronize Sequence Number and ACK means acknowledgment.
• Each step is a type of handshake between the sender and the receiver.
Step 1: SYN
• SYN is a segment sent by the client to the server.
• It acts as a connection request between the client and server.
• It informs the server that the client wants to establish a connection.
• Synchronizing sequence numbers also helps synchronize sequence numbers
sent between any two devices, where the same SYN segment asks for the
sequence number with the connection request.
Step 2: SYN-ACK
• It is an SYN-ACK segment or an SYN + ACK segment sent by the server.
• The ACK segment informs the client that the server has received the
connection request and it is ready to build the connection.
• The SYN segment informs the sequence number with which the server is
ready to start with the segments.
Step 3: ACK
• ACK (Acknowledgment) is the last step before establishing a
successful TCP connection between the client and server.
• The ACK segment is sent by the client as the response of the received
ACK and SN from the server.
• It results in the establishment of a reliable data connection.
• After these three steps, the client and server are ready for the data
communication process.
• TCP connection and termination are full-duplex, which means that the
data can travel in both the directions simultaneously.
TCP Termination
Step 2: FIN_ACK_WAIT
• The client waits for the ACK of the FIN termination request from the
server. It is a waiting state for the client.
Step 3: ACK
• The server sends the ACK (Acknowledgement) segment when it
receives the FIN termination request.
• It depicts that the server is ready to close and terminate the connection.
Step 4: FIN _WAIT_2
• The client waits for the FIN segment from the server.
• It is a type of approved signal sent by the server that shows that the server
is ready to terminate the connection.
Step 5: FIN
• The FIN segment is now sent by the server to the client.
• It is a confirmation signal that the server sends to the client.
• It depicts the successful approval for the termination.
Step 6: ACK
• The client now sends the ACK (Acknowledgement) segment to the server
that it has received the FIN signal, which is a signal from the server to
terminate the connection.
• As soon as the server receives the ACK segment, it terminates the
connection.
Working of TCP
Multiplexing:
• TCP does multiplexing and demultiplexing at the sender and receiver ends
respectively as several logical connections can be established between port
numbers over a physical connection.
Transport Layer 2/2
Process-to-process delivery
TCP 44
Multiplexing and Demultiplexing
Multiplexing
Sender side may have several
processes that need to send
packets (albeit only 1 transport-
layer protocol)
Demultiplexing
At receiver side, after error
checking and header dropping,
transport-layer delivers each
message to appropriate process
TCP 45
Stream Delivery Service
• TCP is a stream-oriented protocol.
• It enables the sending process to deliver data as a stream of bytes and
the receiving process to acquire data as a stream of bytes. (in UDP
divides data bits into datagrams or packets)
• TCP creates a working environment so that the sending and receiving
procedures are connected by an imaginary "tube", as shown in the
figure below:
Full-Duplex Service
• TCP offers a full-duplex service where the data can flow in both directions
simultaneously.
• Each TCP will then have a sending buffer and receiving buffer. The TCP
segments are sent in both directions.
Reliable Service
• TCP is a reliable transport protocol.
• TCP is a reliable protocol as it follows the flow and error control
mechanism.
• It also supports the acknowledgment mechanism, which checks the
state and sound arrival of the data.
• In the acknowledgment mechanism, the receiver sends either positive
or negative acknowledgment to the sender so that the sender can get to
know whether the data packet has been received or needs to resend.
Connection-Oriented Service
• TCP is a connection-oriented protocol.
• When a process wants to communicate (send and receive) with another
process (process -2), the sequence of operations is as follows:
• Connection Establishment: TCP of process-1 informs TCP of process-2 and
gets its approval.
• Data Transfer: TCP of process-1 tells TCP of process-2 exchange data in
both directions.
• Connection Termination: After completing the data exchange, when buffers
on both sides are empty, the two TCPs destroy their buffers
• The type of connection in TCP is not physical, but it is virtual.
• The TCP segment encapsulated in an IP datagram can be sent out of order.
• These segments can get lost or corrupted and may have to be resend.
• Each segment may take a different path to reach the destination.
TCP Features
Reliable
• TCP is a reliable protocol as it follows the flow and error control mechanism.
• It also supports the acknowledgment mechanism, which checks the state and
sound arrival of the data.
• In the acknowledgment mechanism, the receiver sends either positive or negative
acknowledgment to the sender so that the sender can get to know whether the data
packet has been received or needs to resend.
Full duplex
• It is a full-duplex means that the data can transfer in both directions at the
same time.
Stream-oriented
• TCP is a stream-oriented protocol as it allows the sender to send the data in
the form of a stream of bytes and also allows the receiver to accept the data
in the form of a stream of bytes.
• TCP creates an environment in which both the sender and receiver are
connected by an imaginary tube known as a virtual circuit.
• This virtual circuit carries the stream of bytes across the internet.
Advantages of TCP
• TCP provides reliable communication between the communicating
hosts in the network.
• TCP protocol controls the flow of segments.
• TCP protocol controls the error in transmitted segments.
• It provides an error-checking mechanism as well as one for recovery
• TCP includes a congestion control mechanism.
• It makes sure that the data reaches the proper destination in the exact
order that it was sent
• Open Protocol, not owned by any organization or individual
• It assigns an IP address to each computer on the network and a domain
name to each site thus making each device site to be distinguishable
over the network.
Disadvantages of TCP
• TCP is made for Wide Area Networks, thus its size can become an
issue for small networks with low resources.
• All the advantages of TCP produce a large amount of overhead
causing the communication quite slow.
• TCP runs several layers so it can slow down the speed of the network
• It is not generic in nature. Meaning, it cannot represent any protocol
stack other than the TCP/IP suite. E.g., it cannot work with a
Bluetooth connection.
• No modifications since their development around 30 years ago.