Enter in the address bar of the web browser URL Time ,web How is the page rendered ?

        We should know to enter in the web browser URL after , The message will be sent somewhere , Then get a reply from somewhere , Then web The page appears .

        that , A little more detail ,web The browser is specified in the address bar URL, from web The server obtains information such as file resources , Thus showing web page .

        Like this method of obtaining server resources by sending requests web browser , Can be called client .

        web Use a method called HTTP Protocol as specification , Since then, it has completed a series of processes from client to server .

        You can say so ,Web Is based on HTTP Communication over the protocol .

For a more accurate understanding HTTP, We need to know first TCP/IP protocol family .

        The network we usually use , Yes TCP/IP Operating on the basis of protocol family .

        HTTP The agreement is TCP/IP A subset of protocol family .

        You can say so ,

        TCP/IP A protocol is a collection of protocols related to the Internet , Not just TCP Agreement and IP agreement .

        TCP/IP The most important thing in the protocol family is layering .

        TCP/IP The protocol family is divided into four layers according to the hierarchy :

* application layer
* Transport layer
* network layer
* data link layer
       
TCP Benefits of hierarchy : Design for each floor , If a layer appears bugs Or modify , Then there is no need to change the overall design , Each layer of agreement performs its own duties , Just make sure there are no problems with your own aspects .

application layer :

        The application layer determines the communication activities when providing application services to users .

        Like :FTP( File transfer protocol ) and DNS( Domain name system ).

        HTTP The agreement is located in TCP/IP Application layer of protocol .

Transport layer :

        The transport layer provides data transmission between two computers in the state of network connection .

        Contains only TCP( Transmission control protocol ) and UCP( User datagram protocol ) Two agreements of different nature .

network layer :

        Packet is the smallest unit of data transmitted by the network , The network layer is to process the data packets flowing on the network .

        The network layer specifies the path to the other party's computer , And send the data packet to the other party .

        So , The role of the network layer is , When two networks are connected, the data transmission process needs to go through many computers or network devices , Then the network layer selects a transmission route from multiple paths .

data link layer :

        The data link layer is used to deal with the hardware related problems in the process of data transmission , That is to deal with the hardware part connected to the network , Including control operating system , Device driver for hardware ,NIC, Physical visible parts such as optical fiber .

        utilize TCP/IP When the protocol family communicates , They will communicate with each other in hierarchical order , The sender goes down from the application layer , The receiving end goes up from the data link layer .

        Let's take a look at the two computers in the process of data transmission TCP/IP How does the agreement work .

* At the transport layer TCP The protocol converts the data received from the application layer (HTTP Message request ) Split , And mark the serial number and port number on each message , Then forward to the network layer .
* In the network layer , Add as the communication destination in the message MAC The address is then forwarded to the data link layer .
* The server at the receiving end receives data at the link layer , Layer by layer upward transmission , Until transferred to the application layer .
         about HTTP What about the message , At the sending end, each layer is transmitted downward , It must be marked with a header message passing through the layer , conversely , At the receiving end, each layer goes up one by one , Delete the corresponding header for the corresponding .

         The application layer is the transport layer HTTP message , The transport layer is right HTTP Message header addition TCP Message segment , Network layer in HTTP Message header added IP Message segment , The data link layer is the first part of adding Ethernet .

        This method of packaging data information is called encapsulation .

        and TCP/IP On the surface, the effect of each layer of the protocol on data transmission is reflected in the message it adds to the data .

IP agreement :

       
IP The protocol is at the network layer , Its function is to transmit various data packets to each other . And if you want to ensure that it is actually transmitted to the other party , Various conditions need to be met , One of the most important is IP Address and MAC address .

       
among IP The address indicates the address to which the node is assigned ,MAC Address refers to the fixed address of the network card .IP The address can follow MAC Address pairing ,IP The address can be changed , however MAC The address will not change .

       
IP Communication dependency between MAC address , On the network , The two sides of communication are often not in the same LAN , Instead, you need to transfer through multiple computers and network devices to connect to each other . In the process of transit , Will use transit equipment MAC Address to connect to the next target . It will be used here
ARP The protocol is used to resolve the address , You only need to know the name of the correspondent IP The corresponding address can be inversely found MAC address .

TCP agreement :

        TCP The protocol is at the transport layer , It is responsible for providing reliable byte stream services .

        The so-called byte stream service refers to : To facilitate transportation , The block data is divided into data packets with message segments as the unit for management .

        Reliable transmission service refers to , Be able to transfer data to each other accurately and reliably .

        In short ,TCP The protocol divides the data in order to make it easier to transmit big data , and TCP The agreement can confirm whether the data is finally delivered to the other party .

        In order to accurately transmit data to each other ,TCP The protocol adopts a three-time handshake strategy .

        use TCP After the protocol sends out the data packet ,TCP The accurate transmission will be verified , Use here TCP Two targets of :SYN and ACK.

        The sender sends a band first SYN Identify the packet to the other party .

        After receiving , Return a tape SYN/ACK Marked data package to convey confirmation information .

        last , The sender returns another band ACK Marked packet , The representative shook hands .

DNS service :

        DNS Service follow HTTP All protocols are located in the application layer , It provides domain names to IP Address resolution service .

        Computers can be given IP address , It can also be given a host name and domain name .

        Compared to IP For a large number of addresses , The letter combination of host name and domain name is often more consistent with the human memory module .

        But, uh , When you send a domain name , This way of thinking in line with human beings is not understood by computers , therefore DNS Service is necessary .

        DNS Service search by domain name IP, Or from IP Domain name found in address .

        I know that , Let's go through the process of data transmission again :

* First, the client initiates a request for the target domain name
* adopt DNS The service resolves the domain name into IP address
* HTTP Generate request message
* At transport layer TCP Divide the data into multiple message segments , Reliably transmit each message segment to the other party .
* In the network layer IP The protocol can continuously select lines , In many routers, transfer while transferring .
* Connecting hardware through data link layer , Pass on to each other
* The other party uses the data link layer to connect with the hardware for receiving
* In the other party's transport layer ,TCP The protocol reorganizes the sequenced message segments transmitted .
* In the application layer ,HTTP The protocol processes the received request ,
* The result of the request is transmitted back in the same way .
        Reference books :《 graphic HTTP》 Ueno Xuan Write Yu Junliang translate

Technology