[Network] - browser, enter the URL after all what happened?

Browser after entering the URL have what happened?

(This is often said to be the finale of the interview questions to ask the interviewer as)

When we enter the browser www.baidu.com, the browser how to display the final page out of it? Overall this section can be divided into two parts:

1, the communication network
2, page rendering

1, the communication network

Internet communication each network device follow TCP / IP protocol, using the TCP / IP protocol suite for network communications, will communicate to each other through a hierarchical order. Descending hierarchical respectively: the application layer, transport layer, network layer, data link layer. After the layers of the package data, as shown in FIG:
Here Insert Picture Description
1, input url, resolve the domain name in the DNS application layer browser

Www.baidu.com input in the browser, the client first checks whether the local IP address corresponding to, if the corresponding IP address is returned, if the request is not found higher DNS server, or to know where to find the root

2, the application layer client sends an HTTP request

HTTP request includes a request header and request body in two parts, of which the request header contains the request method (GET / POST), target url, protocols (http / https / ftp ...) follow the returns of small information whether the cache and the need to send cookie Wait

3, the transport layer TCP transport packets

Located on the transport layer protocol is divided into chunks of data units in a segment management data packets, and their number, can accurately restore the convenient information server receives the packet. By TCP three-way handshake to ensure the safe and reliable transport. Here again that the review process under the three-way handshake.

A first transmitting side transmits the data packet with the SYN flag of the receiving side and wait for a response within a certain time. After the receiver receives the request, transmits immediately simultaneously with the SYN flag and an acknowledgment ACK reply data packet, said he received a reply, transmits a data packet with the ACK flag of the receiving terminal receives again the receiver, indicates the handshake success. In this process, if the transmitting side receives no reply within a predetermined period of time, the default recipient does not receive a request, sent again until a reply is received.

4, the network layer protocol IP address query MAC

An IP protocol is the TCP segmentation various good packets to the receiver, to ensure that the package is indeed capable to a receiver side, the receiver also needs the MAC address, IP address and MAC address is one relationship , an IP address of the network may change, but the MAC address is constant. ARP protocol can be resolved to the IP address corresponding to the MAC address, if two hosts not in the same local area network, it will be repeated transit

5, data arrives at the data link layer

After finding the MAC address, it will send the data to the data link layer transmission, this time, the client sends a request to the end of the stage.

6, the server receives data

Receives service data in a data link layer, layer up again until the application layer. This process includes the TCP protocol in the transport layer by the fragmented packets reconstituted original HTTP request.

7, the server response to the request

After the server receives an HTTP request of the client, find the resource requested by the client, returns a response message, the response message including an important message - some common status codes 200 ok indicates that the request was successful.

8, the server returns the file

After the request is successful, due to the Content-type header to "text / html", the server returns the corresponding HTML file.

9, the release of a TCP connection

In fact, the connection is released four times waved process:
the browser where the host sends a connection release message to the server, and then stops sending data;
the server receives a confirmation message after the release of the message, and then sends the data on the server has not been transferred completely;
after the server data transmission is completed, it transmits a connection release message to the client;
after the client receives the packet, send a confirmation, and then after a period, releasing the TCP connection;

Second, the page rendering

When the browser does not accept all the complete HTML document, it has begun to show this page, the browser receives the packets back, and render the corresponding data rendering mechanism according to the browser. Rendering data, the corresponding page rendering and interaction pace.

The browser sends for additional embedded content in HTML, such as some style files, pictures url, js file url, etc., the browser will resend the request by these url, request process is still read HTML similar process, query domain name, send request redirection. However, these static files can be cached in the browser, sometimes do not need to access these files through the server, taking directly from the cache. Some sites also use third-party CDN hosting these static files.

Published 42 original articles · won praise 13 · views 1759

Guess you like

Origin blog.csdn.net/Vicky_Cr/article/details/105188929