# TCP and UDP

## **<mark>What are TCP and UDP?</mark>**

### TCP → reliable, ordering of packets maintained, loss detection =&gt; Retransmission possible, Congestion control

TCP happens through 3 way handshake

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769786032543/135ef2f7-58b9-43ae-8eff-61271e980197.png align="center")

  
UDP :-  
Less reliable (not unreliable😅)  
NO retransmission if data packets lost  
very fast  
no 3 way handshake.

## <mark>Key differences between TCP and UDP</mark>

TCP is reliable and more safe but UDP is fast (the main key difference)

## <mark>When to use TCP</mark>

When you want a secure connection between server and client. USE TCP.  
When you want very high speed then use UDP.

## <mark>Common real-world examples of TCP vs UDP</mark>

Real world examples :-

1. TCP → Whatsapp chat → We definitely dont want my chats getting leaked to someone else.
    
2. UDP → In game where latency matters like pubg, free fire etc. OR in live matches of IPL where its not possible to establish a connection between so many users in lakhs.
    

## <mark>What is HTTP and where it fits</mark>

HTTP is a protocol which tells how data will flow from server to client.

## <mark>Relationship between TCP and HTTP</mark>  
  
TCP tells that how the data will be sent and HTTP is what data will be sent. Thus, http has various requests like GET, POST, PUT etc. so http and tcp goes hand in hand
