Front-end and back-end network data transmission

Abstract: It mainly focuses on the work of the browser, including the browser processing user interaction, sending network requests, processing and rendering after receiving the network response, etc.

Front-end :

mainly focusing on the work of the browser, including the browser processing user The interaction

between the

browser itself and the user basically does not involve network knowledge, but the design and implementation of the web front-end UI is a front-end development and siege lion. The most common thing that must be mastered (mainly related to JS) to

send a network request is "starting by entering the URL in the address bar...", which mainly involves the related processing of the client browser and the network module of the operating system.

The browser will check and analyze the URL, involving the validity of the URL and the protocol corresponding to the URL (the most common one is the HTTP protocol, which is also the default network protocol of some browsers); if the URL is legal, it will check whether the HOST in the URL is a Domain name (Domain) is still an IP address; if it is an IP address, the request will be sent directly, otherwise it will check whether the local HOSTS file of the system has the corresponding configuration, if not, the DNS (Domain Name System) protocol will be enabled to query the IP address corresponding to the domain name; When a request is sent, the work of the browser is temporarily terminated, and the network request is handled by the operating system. It is worth noting that if it is a new network machine or the local area network has just recovered from a network failure, the operating system may also use the ARP protocol (Address Resolution Protocol) The MAC address of the egress route is obtained, so that the data packet can be handed over to the router, and the router will forward it to the external network; the analysis and processing of the network request data packet by the operating system protocol stack is another content (mainly related to the difference of different network levels). network protocol)

to handle network responses and rendering

This is the knowledge that traditional front-end engineers must master. For resource-based network responses (such as DOC documents, ZIP archives), the browser will intelligently handle the download; if the corresponding content is renderable plain text, it will be handed over to the front-end program. A reasonable layout is "paved" into the page; the parsing and reality of the page code (HTML/CSS) is realized by the rendering engine of the browser. Different browser rendering engines may have different strategies. There are some points that need to be paid attention to. Engineers also have this knowledge.

Background:

mainly involves the processing of network requests by the web server (not the "hardware server" like a big blade). It can be intuitively considered that a Web server is a network application program that accepts and processes network requests of certain protocols sent by the browser, and returns the corresponding processing results to the client browser. Mainstream web servers include Apache/IIS/Nginx/Tomcat (different web server programs are matched with different background scripting programming languages ​​or technologies to process network requests. For example, Tomcat is mainly matched with JSP language, and Microsoft's IIS is mainly matched with ASP/ASPX technology. ); the web server can usually accept static requests and return static content directly, but when encountering requests for dynamic content (most of the current web applications are dynamic), the web server will entrust the request to the “web background” developed by various languages ​​and technologies Program", the background program processes the dynamic request, and then sends the processed result (response content) to the Web server, and finally the Web server returns the response to the client browser through the Internet. The details of this aspect are mainly the architecture, development, and optimization technology of the background program.

Network data transmission:

The division of the Internet hierarchy (such as the ideal OSI seven-layer model and the practical TCP/IP four-layer network model), each level The main network protocols, routing principles, etc.

The Internet is divided according to various standards, such as local area network, metropolitan area network, and wide area network according to network scale and geographical relationship; There are some technologies in various sub-categories, such as NAT (Network Address Translation) technology for private address and public address translation, various details of different protocols in different layers of the

Internet (packet structure, operation strategy) For example,

the . Necessary knowledge for personnel in the field of operation and maintenance and network security

Let 's talk about the basic process of HTTP request

First of all, HTTP is an application layer protocol. The protocol at this layer is just a communication specification, that is, because the two parties need to communicate, You have to agree on a standard

connection

When we input such a request, we must first establish a socket connection, because the socket is established through ip and port, so there is a DNS resolution process before, turning the domain name into ip, if the url is in If the port number is not included, the

DNS process of the default port number of the protocol will be used : DNS

will be filled in when configuring the network on our local machine, so that the machine will send the url to the configured DNS server, if it can be found The corresponding url returns its ip, otherwise the DNS will continue to send the resolution request to the upper-level DNS. The entire DNS can be regarded as a tree structure, and the request will be sent to the root until the result is obtained. Now we have the target ip and port number, so we can open the socket connection

request

After the connection is successfully established, it starts to send a request to the web server. This request is usually a GET or POST command (POST is used for the transmission of FORM parameters). The format of the GET command is: GET path/filename HTTP/1.0

The filename indicates the file being accessed

HTTP/1.0 indicates the HTTP version used by the web browser The GET command can

now be sent: GET /mydir/index.html HTTP/1.0

response

web The server receives this request and processes it. Search for the file index.html in the subdirectory mydir from its document space. If the file is found, the web server transmits the content of the file to the corresponding web browser.

In order to inform the browser, the web server first transmits some HTTP header information, and then transmits the specific content (ie HTTP body information), HTTP header information and HTTP body information Separated by a blank line

Commonly used HTTP header information are:

HTTP 1.0 200 OK This is the first line of the Web server's response, listing the HTTP version number and response code the server is running. The code "200 OK" indicates that the request is completed

MIME_Version: 1.0 It indicates the version of the MIME type

content_type: type This header is very important, it indicates the MIME type of the HTTP body information. For example: content_type: text/html indicates that the transmitted data is an HTML document

content_length: length value which indicates the length (bytes) of the HTTP body information to

close the connection

When the response ends, the web browser and the web server must disconnect to ensure that other web The browser is able to establish a

connection

Original link[url] http://click.aliyun.com/m/23945/[/url]

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326616900&siteId=291194637