How is the network connected: Web browser / Application

A journey of exploration

1. when the input from the browser URL (Uniform Resource Locator), the browser will start from URL (URL) analysis.
2. according to the parsed data to generate a request message.
3. browser client operating system to the Web server to send the request and tell the system receiver IP address (browser DNS server to query the domain name the corresponding IP address
) 4. of the world’s tens of thousands of DNS servers relay to complete the IP address query
query IP address 5., send a message to the Web server

HTTP request

brief introduction

HTTP (Hypertext Transfer Protocol) translated as “Hypertext Transfer Protocol” was launched in 1989 in the European Organization for nuclear research, the World Wide Web Consortium and the Internet Engineering Task Force “standard — HTTP 1.1. in May 2015 to RFC 7540 released version 2.
HTTP’s primary purpose is to provide a method issuing and receiving HTML page. The resource requested by the HTTP or HTTPS protocol is a uniform resource identifier by the uniform resource identifier:
(URI: Uniform, Resource, Indentifier)

Generating a HTTP request

When we fill in the input box URL, for example: At the beginning of the http:// is what we are going to talk in detail. Note: now most of the site are introduced to safety “HTTPS”, that behind the security mechanism of
. In addition to http://, as well as ftp:// file:// mailto://.
has many types, mainly the reason is because the browser supports many functions, can be used in the FTP server upload / download files using ftp://
file to read the local client using file://
to send electronic mail mailto:// here, do not list, we know that at the beginning of the content is what role can be.

The first part can be interpreted as the type of agreement that is accessed, although the wording is different at the beginning, but the beginning determines the wording behind, so there is no confusion

1.HTTP defines the contents and steps of interaction between the client and the server, the client sends the request to the server includes two contents: “what”, “how to operate”
“for what” mentioned above is also known as URI, for example: “/dir/ index.html” and “/dir/program.cgi”, a web page stored data file name or is a CGI program (Web server program calls other programs called rules) file. The function of URI more than these, there can be a direct use of the “http:” at the beginning of the URL as a URI, can write all kinds of access to the target. URI.
“referred to what actions”: is our common example Get Post, Head, Options, Put, Delete, Trace, Connect, through this method to the server’s data “crud”
2.Web server receives the message. According to URI analysis, and returns the response message, at the beginning of the response message has a status code, we can use the status code returned to judge the news of success or failure, failure.
3. when the browser receives the Web response message from the server, regardless of success or failure, will response the data is displayed on the screen.
4.HTTP the work done

Request header

When URL can’t fully meet the conditions we need, we need to add some additional information in the request that will be used at this point in the head (HTTP header field list)

Response header

When a message is sent to the Web server, you will receive a response message corresponding to the request, and the only difference between the head in the first line, the first line of the content for the state and the response that phrase, the execution of the request. Status code is a number, it is used to inform the implementation of the results to the program, the following table lists the state the basic outline code:

Status code Meaning
1XX Progress and status of request processing
2XX Success
3xx Further operations required
4xx Client error
5xx Server error

When the web page information for the text, is directly displayed on the screen, the request to the end, if there is a need to display picture resources, insert tags in the source code, used to take pictures showing the location and service request to get the response picture displayed in the reserved space.
note: each picture will request to the server one time, such as 3 pictures, a URI, you need to request to the server 4, request and response are one to one. (in HTTP1.1 have been optimized, when a request is completed, the server will not close operation, when all the data request is completed, the browser / client to initiate the close operation)

Query the DNS server for the corresponding IP address of the domain name

Here we do a brief introduction of the IP TCP/IP network is composed of numerous subnet, subnet by sending to the hub, forwarded to the nearest router, the next will automatically judge whether the router to send a message, through continuous transmission, finally arrive at the designated router and the subnet is IP. The address, such as the reality of the XX XX room, equivalent to the message and access the target address.
tip: in the IP address cannot distinguish the network number, host number through the subnet mask this additional information to distinguish.

There is a problem of efficiency, improve the efficiency of domain name to IP address, because the IP address length is 32 bits (4 bytes), relative domain shortest dozens of bytes, 255 bytes in length, reducing the burden of the router to transmit data, the time is relatively reduced.

The conversion mechanism between the domain name and IP address is called a DNS.
so, DNS is how to query IP? It is actually very simple, is included in the call “Socket library” in the parser, when we come through the DNS IP query, the parser invokes the results in Socket, stored in the browser in the memory of the browser to the Web server to send messages, with the return to the operating system is analyzed from the memory out of the corresponding IP address and HTTP
. A word: domain name query IP address, the browser will use the Socket parser in the library

So, how does the parser work inside?

The internal implementation principle of the parser

Here is a brief overview:
1. browser / IP memory space = app store using advanced programming language, using Socket library according to the domain name to call the method
2.Scoket library generated query message sent to
DNS server 3. entrusted to the operating system protocol stack will send out messages (operating software, internal network control the system also called TCP/IP drive)
4. with the card sent to the DNS server
5. query results to return query results through the network card and stored in memory
6. to continue the next line of code to call time out queries to the IP address in the corresponding memory

As long as the tip: is registered in the DNS server, the Web server can be used as the domain name to use
a word: the DNS server from the domain name and IP address control to find the corresponding record in the table and returns the corresponding IP address

When the query is submitted to the DNS server, the DNS server will first find the nearest query, if the query to the IP address in the root domain, then, according to the current DNS server stores the root domain information to find the IP address, until to check so far.
DNS service optimization server:
by 1. the DNS server a Downlevel server IP address, can also send queries to the superior
2.DNS server using the
distributed storage mode 3. query IP address will be cached, the cache time and will set the corresponding query. In response, the DNS server will inform the client from the cache or the domain name management the DNS server.

Some of the content mentioned above will extend the solution later