So guys, now I am summarizing the difference between TCP protocol and UDP protocol all at one place.
So point number one says that TCP protocol is a slower and complex service, whereas UDP protocol is
a simpler and fast service.
Right.
Point number two says that TCP protocol is a connection oriented protocol.
That is, the TCP has to establish the connection with its peer before carrying out any actual data
exchange, whereas UDP protocol is a Connectionless protocol.
TCP is a stateful protocol, whereas UDP is a stateless protocol.
I have already explained these terms in great detail.
TCP protocol is a reliable protocol, whereas UDP protocol is an unreliable protocol.
Reliable means that TCP protocol can recover lost packets, detect malformed corrupt packets and react
to the congestion in the network.
TCP also preserves the order of packets.
The protocol, on the other hand, is unreliable.
There is no such mechanism to recover the lost packet.
A packet which is lost or corrupted is gone forever and UDP also do not guarantee any in-order delivery
of packets to the recipient.
TCP is a byte oriented protocol.
That is, it keeps track of the data at the byte level, whereas UDP is a datagram oriented protocol.
Now when I say that UDP is a datagram oriented protocol, it means that UDP encapsulates or packages
the application data to form a small chunk of units of data called datagrams.
But still UDP do not keep track of these datagrams, whether datagrams are lost or received by the receiver
or not.
UDP absolutely do not keep track of any data.
TCP protocol is used if the applications which are involved in the communication needs reliability.
Reliability means that they are involved in exchanging critical data.
It simply means that even if some packets of the data is lost, then it will be leading.
Then it will lead to disastrous situation.
Right.
So the example is that, for example, suppose you are downloading a software package from some remote
server, right?
So even if one byte of data is missed, your software package will be corrupted and it may not run or
even if run, it will run erroneously.
So while downloading a software package, it has to be ensured that all the bytes of the software package
have been downloaded correctly.
Whereas UDP protocol is used in the scenario where applications involved in communication do not need
reliability and can actually tolerate some packet loss.
For example, you are doing hangout or you are actually doing video conferencing on Skype.
In such type of communication.
Even if some packets get lost, the recipient would hardly notice any noticeable change in the quality
of audio or video, even if recipient noticed some change in the quality of audio or video, then that
particular change is very short lived and transient and loss of few packets in audio or video streaming
do not impact the overall experience of this audio or video conference.
Now, this is the most asked questions in the interviews that explain the scenarios in which you would
like to establish communication between the application using TCP protocol and not UDP protocol and
explain the scenarios in which you would prefer UDP protocol over TCP protocol.
So you should really browse the internet and find out the scenarios where you would prefer TCP over
UDP and vice versa.
So I would suggest browse the internet, take some time out and understand the applications in which
you would prefer TCP over UDP and the applications in which you would prefer UDP or TCP.
This is actually a very important questions often asked in interviews, so be prepared for it and I
would suggest take some time and do some readings on the internet.