When we search for any website over the internet, there are many process that occurs to get our desired result.
Here are the steps :
- DNS Resolution
- Establishing a TCP connection
- Sending HTTP Request
DNS Resolution - This step invloves converting the domain name to the IP Address
. when someone enters a URL in the browser, then a request is sent to the DNS serves which reverts with the IP Address. The IP address tells us where the server is present which hosts the particular website.
Establishing a TCP Connection - After we get the IP Address , Our browser initiates a TCP connection with the web server at that IP Address. This process involes a 3-way handshake.
- SYN(synchronize) Packet - Our browser sends a SYN packet to the server to initiate the connection. It is the 1st packet sent from client to server. It contain serveral fields such as source port, destination port, sequence number [ It is used to ensure the data integrity. ]
- SYN-ACK (Server to Client) - The server responds with a SYN-ACK packet, acknowledging the client’s SYN and providing its own initial sequence number.
- ACK (Client to Server): The client sends an ACK packet back to the server, acknowledging the server’s SYN-ACK. This completes the handshake, and the connection is established.
A Established TCP connections ensures that the data is transmitted properly. But TCP can't dictate how is data is structured and interpreted , so we use HTTP on the top TCP. HTTP (Hypertext Transfer Protocol) operates on top of TCP. Since HTTP is a stateless protocol, it relies on TCP to maintain the order of data transmission. Without TCP's sequencing mechanism, the HTTP protocol wouldn't guarantee that web pages and resources are delivered and rendered correctly.
Sending HTTP Request - After Establishing the TCP connection our browser sends the HTTP request to server. The Request got processed on the server and send the response which is then rendered by the browser.
Extras
- HTTP is stateless, meaning each request-response cycle is independent of previous interactions. It follows a request-response model.
- Websocket is also a communication protocol that provide full-duplex communication over single TCP connection. It enables real-time, bidirectional communication between a client (such as a web browser) and a server.
- TCP is a Transport layer protocol & HTTP or websockets are Application layer protocol.