You sent a message
One protocol says , "Wait did it reach safely?"
The other says , "I sent it . Not my problem"
In this blog we will see who is better TCP , UDP and for sure we will come to a conclusion .
Topics we will cover :
What are TCP and UDP ( at very hight level ) ?
Key difference between TCP and UDP
When to use TCP ?
When to use UDP ?
What is HTTP and where it fits ?
Relationship between TCP and HTTP
TCP and UDP
TCP :- Transmission Control Protocol
It is a type of network protocol that :
Transfer the data over the internet from your device to web server
It established the connection first between sender and receiver with 3 - way handshake .
It make sure the data sending over the network reaches at its destination .
It is slow as compare to UDP but it is reliable as it minimizes the out of order and loss of data packets .
Examples :- Chatting apps , messaging , emails , file download
If you want to know more about TCP . I strongly recommend you to read this blog. π
TCPβs Trust Issues: A 3-Way Handshake Story
Kunal γ» Jan 23
UDP :- User Datagram Protocol
It is a type of network protocol that :
It transfer the data over internet from your device to a server
Unlike TCP , It does not create a connection first like TCP does via 3-way handshake
It simply sends the data to receiver without checking the missing packet or out of order packets .
UDP is less reliable as packet loss and out of order delivery is possible
Example :- Video calling , Streaming , Online gaming
Did you feel buffering sometimes when you Video call your friend ? Now you can understand why π
Key differences between TCP and UDP
| TCP | UDP |
|---|---|
| Connection-oriented | Connectionless |
| Uses 3-way handshake | No handshake |
| Reliable (guarantees delivery) | Less reliable |
| Maintains packet order | Packets may arrive out of order |
| Slower | Faster |
| Error checking & retransmission | No retransmission |
| Used in chats, emails, downloads | Used in streaming, gaming, live calls |
When to use TCP ?
π You should use TCP when :
You want to Chat with someone where there needs to send the data correctly .
The missing of data packets are not acceptable .
When you send an important email to someone you cant expect the curroption of your mail even if it get transfer slowly to the receiver .It reaches without any error thats the main concern .
When to use UDP ?
π You should use UDP when :
Speed matter more than perfection .
Small data loss is acceptable .
When you Video call your friend you need a internet fast enough to transfer your message . You just want to talk not much care about the loss of data packets .
The next question is How the browser use these protocol to load the website ?
What is HTTP and where it fits ?
HTTP :- Hyper Text Transfer Protocol
Example : You open Facebook in your browser
- You wrote the URL in the browser and press enter
www.facebook.com
- Your browser sends a HTTP requet to the fb web-server
The request looks like π
GET : /HTTP/1.1
HOST : www.facebook.com
- This web server process your request . That checks :
What page you have asked for ( eg:- Home page , Login page )
Checks wheather you have previously logged in or not . ( if you are logged in then it shows a different page )
If it get processed then .
- Server sends an HTTP response to your request
The response looks like π
HTTP/1.1 200 OK
Content-Type: text/html
Meaning here is the page you have asked for.
Now you understand how the browser loads a websiteπ
TCP/UDP :- decides how the data is transfered
HTTP :- decides what it request and what to send back
Where this HTTP fits π€
π HTTP sits on the top of TCP and uses it to deliver web data reliably .
Why TCP why not UDP lets now understand the relationship between HTTP and TCP
Relationship between TCP and HTTP
As we know that HTTP only defines what data to send , not how to send it safely
That where TCP come in .
TCP makes the connection reliable
It sends the data in correct order
It also retransmit the data if lost
So, HTTP talks and TCP make sure that the message is delivered properly .
Thanks for reading ! if enjoyed this blog , you can read more on this π

Top comments (0)