From the user's browser, enter the URL after the carriage return, the browser do what

Before performing the steps listed directly first to popularize some knowledge, I believe around will end after the completion of knowledge about these interactions have a deeper understanding.

1, TCP connection

TCP: Transmission Control Protocol, Transmission Control Protocol, a connection-oriented, reliable transport layer protocol based on the byte stream.
Say so professional, dim it?
First to give it chestnuts
remember when we did it cups the phone? Two paper cups connected together by a rope, two each holding a paper cup straighten the line, facing a paper cup speaking, listening with a paper cup in front of the ears.

This is actually one of the simplest communication connection, the two are connected by a line, the sound transmission through the receiving line to another paper cup, now extended to every household has a landline is true from the side of the cup, it's communication is built on trust and mutually acceptable basis carried out, such as:

  1. A pick up the phone, dial 0775-6532122, starts the call B
  2. B hear the phone rang, pick up the phone, then A receives B has picked up the phone's voice
  3. The two sides began to speak

Returning to our tcp protocol, and in fact it is the above mentioned telephone protocol similar, but phone service agreement is in telephone communications, and tcp is a protocol for network communications service. Similarly, the two sides establish a communication connection tcp also need to go through three steps (handshake).

  1. The client sends syn packets (syn = j) to the server, and enters SYN_SEND state, waiting for the server to confirm.
  2. Syn server receives the packet, must confirm the customer SYN (ack = j + 1), while themselves sends a SYN packet (syn = k), i.e., SYN + ACK packet, then the server enters a state SYN_RECV.
  3. Client receives the SYN + ACK packet to the server, the server sends an acknowledgment packet ACK (ack = k + 1), this packet is sent, the client and server into the ESTABLISHED state, complete the three-way handshake.

Letters above the following meanings:

SYN: synchronous to establish a connection
ACK: acknowledgement confirmation
SYN_SENT: a request for connection  
SYN_RECV: passive open rear end of the service, the client receives and transmits SYN state when the ACK. Further receiving the ACK to the client enters the ESTABLISHED state.

It is worth noting: tcp does not carry data during the handshake, (as you call for hotel reservations, hotel before confirming the other is customer service, you will not immediately reported to him the identity card number, right?) but after three-way handshake is complete, the data will be transmitted .

As for its application scenarios, in fact, is based on the characteristics of its own may be, for example, there are requirements for network communication quality, the need to ensure data accuracy, we need to use the TCP protocol, such as HTTP, ftp, etc. File Transfer Protocol, or Some mail transfer protocol (SMTP, pop, etc.)

2, UDP connection

The UDP  : the User Datagram Protocol User Datagram Protocol
compared to oriented TCP connection requires tedious steps of repeatedly confirmed, UDP is a protocol of the subjective character Maverick and superior non-connection-oriented communication is not frequently used protocol udp need to establish a connection, it is only responsible for sending data out as fast, simple and crude, and unreliable, at the receiving end, UDP-off to each message in the queue, the receiving terminal to read data from the queue.

Some would say, UDP protocol so unreliable, why will make out of it?

Anyway, no useless man under the sun, only with people you do not know it, though UDP is not reliable, but its fast transmission speed, high efficiency and accuracy of data in some of the less demanding scenes, it becomes UDP very useful, such as voice qq, qq video.

3, the word nested Socket

Why say nesting word?
That is because as said earlier, TCP or UDP is a protocol, which is the computer network communication at the transport layer of a protocol, simply put, is a convention, the same as a contract of cooperation, then contract is dead, only the performance of the contract is the substantive action, so either TCP or UDP to have an effect, we need to have the actual behavior in order to reflect the agreement to perform the role,
then, is there any way to make these agreements role in it?
This is to say to the socket.

Socket : also called nested word, is implemented a set of TCP / Interface API UDP communication, i.e. whether the UDP or TCP, by programming the scoket, can be implemented TCP / of UCP communication, communication links as a handle, it communication network comprising five types of information necessary:

  1. Connection protocol to use
  2. IP address of the local host
  3. Local port protocol process
  4. Remote host's IP address
  5. Protocol Port remote process

Visible, socket comprising a communication of the remote and the ip and port, and protocol (TCP / UDP) connection used. One of the communicating parties in the (tentative name: Client) by scoket (nested word) to the other party (tentative name: server) initiates a connection request, the server listens for requests on the network when the client receives a request sent by after that, according to the information carried in the socket, locate the client request accordingly, the socket descriptor to the client, after the two sides confirm the connection is established.
Thus the connection between the socket has three process steps:

  1. Server monitor: real-time monitoring network status server waits for a client to send a connection request
  2. Client request: Client port initiates connection requests from the IP address to which the remote host server protocol
  3. Connection confirmation: the server socket connection request is received after the response to the request, the server socket descriptor to the client, the client receives Once confirmed, the two sides establish a connection for data exchange.

Typically socket connection is a TCP connection, so the socket connection, once established, the communication data exchanged by the two sides start communicating until one or both disconnected so far.

socket widely used in instant messaging (qq and other chat software) applications.

4, HTTP protocol

HTTP protocol : Hypertext Transfer Protocol, also known as the Hypertext Transfer Protocol, which is based on TCP / IP protocol stack, the protocol on the presentation layer and application layer (TCP protocol at the transport layer), popular thing to say is this:

  • TCP / IP is a protocol located on the transport layer, for transmitting data in a network;
  • HTTP protocol is an application layer protocol, based on TCP protocol, for packaging the data, the program uses for communication, simple and efficient transmission and processing of the identification data communications

Now widely used in the HTTP connection is established on the HTTP protocol, a particular application in the application layer.
Speaking above the socket connection once you stay connected, but not the same HTTP connection, which is based on short-tcp connection protocol, that is client-initiated requests, after the server responds to the request, the connection will automatically disconnect, the establishment will not stay .

5、URL

Speaking in front of the tcp, udp, http ... and so on are to talk about a specific issue and pave the way to do knowledge, that is: to initiate and develop web applications to respond to our request, it is a kind of underlying principles.
As we all know, web applications mostly to the request by HTTP, and HTTP URL is used to make a specific implementation of connection establishment and transmission of data, so this should be simple to talk about URL.

The URL of : Uniform Resource Locator Uniform Resource Locator. To put it plainly an address that is used to identify specific resources on the network, contains information for users to find the resources, HTTP use it to transfer data and establish a connection to
a URL has the following components:

  1. protocol
  2. Server address (domain name or IP + port)
  3. path
  4. file name

For example: https: //www.baidu.com/index.html
which

  • https: // is an agreement, of course, HTTP ftp is also ...
  • www.baidu.com server address is, of course, you know Baidu's IP is also possible, for example, I used the ping command to get Baidu's ip14.215.177.39, then I can open Baidu http://14.215.177.39
  • index.html contains the path and file name, of course, usually index.html can be omitted, so when you open Baidu, and did not see this.

6、DNS

The DNS : Domain the Name Server, Domain Name Server.
It is the domain name (domain name) and server with the corresponding IP address (IP address) conversion. DNS is saved in a domain name and an IP address corresponding thereto (IP address) of the table (domain name), the message to resolve the domain name.
In peacetime we develop, provide the back-end interface address is usually the IP address plus port number (8080 what ghost) consisting of, but when we put out the release site, usually with the need to change the IP domain.
why?
Oh, you think about it, such as Google's address is 89.12.21.221:9090, Baidu's address is 132.21.33.221:8766. . .
So you do not see a desire to remember that these figures are a mess, right?
But not the same domain name, such as Google's google.com, Baidu's baidu.com is not again to remember it?
So in order to deal with this problem, we need to use the domain name to IP address mapping, easy to remember and easy to use to achieve the purpose.

Thus, when a user enters https://www.baidu.com Enter in the browser, it went through the following steps:

  1. Browser to locate the address itself to the cache dns resolution records, if any, direct return the IP address or the browser looks for the operating system (hosts file) Is there a record of the domain name dns resolution, if there is returned.
  2. If the domain name dns cache browser and operating system hosts were not resolved in the record, or has expired, this time it will initiate a request to the domain name server to resolve the domain name.
  3. Request will first LDNS (local domain name server), it attempts to resolve the domain name, if LDNS not be resolved, the request directly to resolve the root domain name resolver
  4. LDNS root name server to return a query remainder of the primary domain name server (gTLDServer) address.
  5. At this step the server LDNS gTLD returned upwardly again initiated resolution request.
  6. After gTLD server receives the resolution request to find and return address corresponding to the domain name server Name Server, Name Server usually this is your registered domain name server (dns such as Ali, Tencent, dns, etc.)
  7. Name Server IP of domain names and domain name server queries the stored mapping table, under normal circumstances, have been recorded according to the destination IP domain name, along with a TTL value is returned to the DNS Server Domain Name Server
  8. Return the domain name and corresponding IP TTL value, Local DNS Server will cache the correspondence between the domain name and IP cache TTL value of the time there is control.
  9. The analytical results are returned to the user, the user on the local system cache, DNS cache TTL value in accordance with the process ends.

7, HTTP requests and responses initiated

In a web application development in general, has front and rear ends of the points, responsible for front-end to back-end data requests and display the page, the back end is responsible for receiving the request and respond back to the front, bridge of cooperation between them is what?
API is
what is API? A URL is not it?
URL is Shane? Mentioned above is one specific HTTP connection carrier
Thus,
both for the front end or rear end, HTTP appreciated, both for their understanding of programming, or collaboration with colleagues and are greatly benefits,
below, according to the above respective understand the point of knowledge, we have to sort out and solve what the first question mentioned above:
from user input URL, the browser renders the page to the user, through what process

  1. User input URL, the browser URL to get
  2. Browser (application layer) for DNS resolution (if the input is an IP address, this step is omitted)
  3. According to the parsed IP address + port, the browser (application layer) sends an HTTP request that carries (header request header (the request may be broken down into the first row and the request), the request body body); header comprising : (1) method (get, post, put ..) requested (2) protocol (HTTP, HTTPS, the FTP, SFTP ...) (3) target url (the file has a specific request path name) (4) the necessary information (cache, cookie and the like) body comprising: requesting content
  4. Request arrives at the transport layer, TCP as the transport protocol to provide reliable byte packet streaming service, which by means of three-way handshake to ensure the safety and reliability of the transmission process. To provide large amounts of data by dividing the data into chunks of one embodiment of a portable transmission segment.
  5. To the network layer, the network layer address of the recipient to give Mac the ARP address, IP protocol to transmit data packets is divided into a recipient at the transport layer.
  6. Data reaches the data link layer, to complete the request phase
  7. After the receiver receives the packet data link layer, layer is transmitted to the application layer, receiving application can get the request packet.
  8. After the receiver receives the HTTP request is the sender, the request file resource (e.g., HTML page) search and response packets
  9. After the transmission side receives the response packet, if the packet success status code indicates that the request is accepted the resource (e.g., an HTML file) is returned, for page rendering.

 

Article from: https: //mp.weixin.qq.com/s/G8cx8G-VhUtC6XA1PIysCg, thank the author

Guess you like

Origin www.cnblogs.com/jokmangood/p/11705959.html