DEV Community

Sakshi
Sakshi

Posted on

Complete TCP/IP

TCP IP working

1. Application Layer:

  • Browser Interaction: Your browser (an application) initiates the process by interpreting the URL you clicked. It determines the protocol to use (HTTP or HTTPS) based on the URL.
  • HTTP/HTTPS: If it's an HTTP request (or its secure version, HTTPS), your browser creates an HTTP GET request to fetch the web page's content.

2. Transport Layer:

  • TCP (Transmission Control Protocol): The browser segments the HTTP request into packets. TCP establishes a connection between your computer and the server, ensuring reliable delivery of these packets.

3. Internet Layer:

  • IP (Internet Protocol): IP assigns an IP address to your request and helps route the packets across various networks to reach the destination server.

4. Link Layer:

  • Data Link Layer: This layer ensures the data travels reliably across the physical network. Protocols like Ethernet or Wi-Fi handle how the data is packaged for transmission on your local network.

Server Side:

  • Link Layer (Server Side): At the server's end, the data travels through the link layer on its network before reaching the server's TCP/IP stack.
  • Internet Layer (Server Side): The IP layer routes the incoming packets to the correct server based on the IP address.
  • Transport Layer (Server Side): TCP reassembles the packets into the original HTTP request.
  • Application Layer (Server Side): The server's web server software (like Apache or Nginx) processes the incoming HTTP request, retrieves the requested web page or resource, and prepares an HTTP response.

Return Path:

  • Application Layer (Server to Client): The server sends back an HTTP response containing the requested web page's content or resource.
  • Transport Layer (Server to Client): TCP breaks down the response into packets for transmission.
  • Internet Layer (Server to Client): IP addresses the packets and routes them back to your computer.
  • Link Layer (Server to Client): The data travels through the link layer on the network before reaching your computer.
  • Transport Layer (Client Side): TCP reassembles the response packets into the complete HTTP response.
  • Application Layer (Client Side): Your browser interprets the received HTTP response and renders the web page for you to view.

Suppose you want to check out the latest course offerings from http://codecademy.com. After you type the URL into your browser, your browser will extract the http part and recognize that it is the name of the network protocol to use. Then, it takes the domain name from the URL, in this case “codecademy.com”, and asks the internet Domain Name Server to return an Internet Protocol (IP) address.

Now the client knows the destination’s IP address. It then opens a connection to the server at that address, using the http protocol as specified. It will initiate a GET request to the server which contains the IP address of the host and optionally a data payload. The GET request contains the following text:

GET / HTTP/1.1
Host: www.codecademy.com

Enter fullscreen mode Exit fullscreen mode

This identifies the type of request, the path on www.codecademy.com (in this case, “/“) and the protocol “HTTP/1.1.” HTTP/1.1 is a revision of the first HTTP, which is now called HTTP/1.0. In HTTP/1.0, every resource request requires a separate connection to the server. HTTP/1.1 uses one connection more than once, so that additional content (like images or stylesheets) is retrieved even after the page has been retrieved. As a result, requests using HTTP/1.1 have less delay than those using HTTP/1.0.

The second line of the request contains the address of the server which is "www.codecademy.com". There may be additional lines as well depending on what data your browser chooses to send.

If the server is able to locate the path requested, the server might respond with the header:

HTTP/1.1 200 OK
Content-Type: text/html

Enter fullscreen mode Exit fullscreen mode

This header is followed by the content requested, which in this case is the information needed to render www.codecademy.com.

The first line of the header, HTTP/1.1 200 OK, is confirmation that the server understands the protocol that the client wants to communicate with (HTTP/1.1), and an HTTP status code signifying that the resource was found on the server. The second line, Content-Type: text/html, shows the type of content that it will be sending to the client.

If the server is not able to locate the path requested by the client, it will respond with the header:

HTTP/1.1 404 NOT FOUND

Enter fullscreen mode Exit fullscreen mode

In this case, the server identifies that it understands the HTTP protocol, but the 404 NOT FOUND status code signifies that the specific piece of content requested was not found. This might happen if the content was moved or if you typed in the URL path incorrectly or if the page was removed. You can read more about the 404 status code, commonly called a 404 error, here.

Top comments (0)