The Transmission Control Protocol, TCP, provides a communication service at an intermediate level between
an application program and the Internet Protocol.
It provides host-­to-­host connectivity at the Transport Layer of the Internet model. TCP works with the
Internet Protocol (IP), which defines how computers send packets of data to each other. Together,
TCP and IP are the basic rules defining the Internet. TCP is a connection-­oriented protocol which means
a connection is establish and maintain until the application programs at each end have finished exchanging
messages. It determines how to fragment application data into packets that networks can deliver, sends
packets to accept packets from the network layer, manages flow control and because it is meant to provide
error free data transmission handles retransmission of dropped or garbled packets as well as acknowledgement
of all packets that arrive, Let’s see the connection-­oriented, error-­free communication of TCP in an example:
When a Web server sends a HTML file to a client, it uses the HTTP protocol to do so.
The HTTP program layer asks the TCP layer to set up the connection and send the file.
The TCP stack divides the file into packets, numbers them and then forwards them individually to the
IP layer for delivery.
Although each packet in the transmission will have the same source and destination IP addresses packets
packets may be sent along multiple routes. The TCP program layer in the client computer waits until all of the
packets have arrived, then acknowledges those it receives and asks for the retransmission on any it does
not (based on missing packet numbers), then assembles them into a file and delivers the file to the receiving
application.
The TCP three-­way handshake is the method used by TCP to set up a connection. TCP's three way handshaking
technique is often referred to as SYN, SYN-­ACK, ACK because there are three messages transmitted by TCP
to negotiate and start a TCP session between two computers. This 3-­way handshake process is also
designed so that both ends can initiate and negotiate separate TCP socket connections at the same time.
That means, the connection is full-­duplex.
Oh you know what we have to take a break at this point and talk about TCP flags.
There are 1-­bit flags in TCP headers which are called TCP flags. TCP flags are used within TCP packet
transfers to indicate a particular connection state or provide additional information.
Ignoring ECE, CWR and NS flags for now, there are basically 6 TCP flags:
The SYN, or Synchronisation flag, is used as a first step in establishing a 3-­ way handshake between two hosts.
Only the first packet from both the sender and receiver should have this flag set. The ACK flag, which
stands for “Acknowledgment”, is used to acknowledge the successful receipt of a packet.
The RST flag, which stands for “Reset”, gets sent from the receiver to the sender when a packet is sent to
a particular host that was not expecting it. The FIN flag, which stands for “Finished”, means there is no more
data from the sender.
Therefore it is used in the last packet sent from the sender.
The PSH flag, which stands for “Push”, is somewhat similar to the URG flag and tells the receiver to process these packets
as they are received instead of buffering them. The URG flag is used to notify the receiver
to process the urgent packets before processing all other packets.
OK now we can continue to talk about TCP’s three-­way handshake.
STEP 1: Computer A sends a SYN data packet to Computer B. SYN data packet means, the data packet
where the SYN flag of the TCP header is set.
Well, what does setting the SYN flag mean? T
hat means, making the SYN bit 1. The objective of this packet is to ask if Computer B is open for
new connections.
Computer B must have open ports that can accept and initiate new connections.
STEP 2: When Computer B receives the SYN packet from Computer A, it responds and returns a confirmation receipt
the SYN/ACK packet. As you understand, SYN/ACK packet means the packet in which the SYN and the ACK flags are set.
STEP 3: Computer A receives the SYN/ACK from Computer A and responds with an ACK packet.
At this point, both computers have received an acknowledgment of the connection. With these, a full-duplex
communication is established.
UDP is another protocol of Transport Layer, Layer 4, used primarily for establishing low- latency and loss
tolerating connections between applications on the Internet.
TCP has emerged as the dominant protocol used for the bulk of Internet connectivity owing to its services
for breaking large datasets into individual packets checking for and responding lost packet and reassembling
packets into the correct sequence.
But these additional services come at a cost in terms of additional data overhead and delays called
latency.
In contrast UDP just sends the packets.
Which means that it has a much lower bandwidth overhead and latency but packets can be lost or received
out of order as a result.
Owing to the different paths individual packets traverse between Center and receiver.
So UDP uses a simple connection less communication model with a minimum of protocol mechanism.
It has no handshaking dialogs and thus exposes the user's program to any unreliability of the underlying
network.
There is no guarantee of delivery ordering or duplicate protection.
UDP is suitable for purposes where error checking and correction are either not necessary or are performed
in the application. UDP is an ideal protocol for network applications in which perceive latency is critical
such as gaming voice and video communications which can set for some data loss without adversely affecting
perceived quality.
In addition since it's transaction oriented suitable for simple query response protocols such as the
domain name system or the network protocol.