1. Enter url in webpage, render the whole process of the whole interface, and what protocol is used in the middle?
Process analysis: mainly divided into three steps
The DNS. After entering the URL, the user needs to find the IP address corresponding to the domain name through DNS resolution. After the IP address is found, the user can find the server. The browser cache is searched first to see if there is a corresponding DNS record. Then, perform DNS resolution in the sequence of operating system cache, route cache, ISP DNS server, and root server until the corresponding IP address is found. The client (browser) interacts with the server. The browser makes an HTTP request based on the resolved IP address and port number. The request reaches the transport layer, in this case the TCP layer, and the three-way handshake is initiated to establish the connection. After receiving the request, the server sends a packet to the client (browser). The client receives the packet and parses it to obtain HTML data, including HTML, JS, and CSS. The client parses the HTML data, builds a DOM tree, constructs the render tree, and finally draws it onto the browser page. It involves TCP/IP protocol cluster, including DNS, TCP, IP, HTTP and so on.
2. This section describes TCP/IP
TCP/IP refers to the TCP/IP protocol cluster, which consists of the following layers: ** Application layer: ** Provides data and services. For example, HTTP, FTP, DNS, etc. ** transport layer: ** is responsible for data assembly, block. Such as TCP, UDP, etc. ** Network layer: ** is responsible for telling the destination of communication, such as IP, etc. ** Data link layer: ** is responsible for connecting the hardware part of the network, such as Ethernet, WIFI, etc
TCP (Transmission Control Protocol) – Communication between applications. When an application wants to communicate with another application over TCP, it sends a communication request. The request must be sent to an exact address. After a “handshake”, TCP establishes a full-duplex communication between the two applications. This full-duplex communication will occupy the communication line between the two computers until it is shut down by one or both. IP (Internet Protocol) – Communication between computers. IP is a connectionless communication protocol. It does not occupy the communication line between two communicating computers. In this way, IP reduces the need for network lines. Each line can meet the communication needs of many different computers simultaneously. With IP, messages (or other data) are divided into small independent packets and sent from computer to computer over the Internet. IP is responsible for routing each packet to its destination.
TCP three handshakes and four waves, why not two handshakes? Why wave more? A sends A SYN packet to B. B receives A SYN packet, indicating that I am ready to connect with you. B needs to confirm the SYN packet received by B and sends A SYN packet of its own. After A SYN + ACK packet is sent, B enters the SYN_RECV state. A receives A SYN + ACK packet and sends an ACK packet to B. AB enters the Established state.
2) TCP disconnection requires four waves (A sends A FIN message to B and enters the FIN_WAIT_1 state). B receives A message, but the message is not finished. It can only tell A THAT I have received your disconnection message (B receives A FIN, sends an ACK, and enters the CLOSE_WAIT state). After B sends the data, tell A that I can disconnect from you (B sends the FIN and enters the LAST_ACK state). A receives the message and tells B that it can disconnect from you (A receives the FIN and sends the ACK, and B enters the closed state).
3) Why do you wave more than once? In fact, normal disconnection and connection require four times: A sends A message to B, and B sends A message to A, and A sends A message to B, and B receives A message correctly. But in the join, the second and third steps can be combined, because A and B are unconnected before the join, so there is no other case to deal with. In the case of disconnection, since both ends were normally connected before, the second step cannot guarantee that the message sent by B has been completed, so A cannot be informed of the message to be disconnected immediately. This is why the connection can be one step less.
4) Why does the connection need three times instead of two? Normally, if I send you a message and you tell me I can receive it, doesn’t it mean that our previous communication is normal? The short answer is that TCP is A two-way communication protocol. If you shake hands twice, the message sent from B to A will not arrive correctly. To ensure reliable transmission of TCP packets, both communication parties need to check whether the packets they have sent are received by the receiver. If they are not received, they need to resend the packets.
3. How does TCP ensure reliable transmission?
** Serial number and confirmation number. ** For example, if one side of the connection sends an 80byte piece of data, it will carry a sequence number, such as 101. The recipient receives the data and replies with the acknowledgement number 181 (180+1), so that the next sent message will be sent from 181. Therefore, during the handshake, for example, USER A sends A SYN signal to user B with the initial sequence number 120. Then, user B receives an ACK message with the sequence number 120+1. At the same time, B sends the SYN signal to A with the initial sequence number of 256. If it does not receive the reply message from A, it will resend the syn signal. Otherwise, the subsequent communication cannot be normally completed if the sequence number is lost. That’s the reason for the three handshakes.
TCP/IP Details – The four stages of congestion control
1. Slow start phase
When starting a connection, old TCP sent many packets to the network. Because some routers had to queue the packets, they could run out of storage space, resulting in a steep drop in throughput of TCP connections. The algorithm to avoid this is slow start. When a new TCP connection is established, the congestion window is initialized to a packet size (a packet defaults to 536 or 512 bytes). The source sends data by CWND size, and the CWND sends an additional packet for each ACK it receives. Obviously, the growth of CWND will increase exponentially with RTT: 1, 2, 4, 8… . The amount of data sent from the source to the network increases dramatically.
2. Congestion avoidance phase
Network congestion occurs when a timeout is detected or three identical ACK acknowledgment frames are received (this is the practice of TCP Reno, which assumes that the probability of packet corruption and loss due to transport is less than 1%). At this point, the congestion avoidance phase is entered. The slow start threshold is set to half of the current CWND; On timeout, CWND is set to 1. If CWND ≤ SSTHRESH, TCP restarts the slow start process. If CWND > SSTHRESH, TCP performs the congestion avoidance algorithm and CWND only adds 1/ CWND packets each time it receives an ACK (segsize of packets is assumed to be 1 here).
3. Fast retransmission and recovery phases
When the packet times out, the CWND is set to 1, re-entering slow start, which results in drastically reducing the size of the send window and reducing the throughput of the TCP connection. Therefore, fast retransmission and recovery means that when the source receives three or more duplicate ACKS, it determines that the packet has been lost, retransmits the packet, and sets SSTHRESH to half of the current CWND without waiting until the RTO times out. Figure 2 and Figure 3 reflect the change of congestion control window over time in four stages.
4. What is the difference between TCP and UDP?
TCP provides a connection-oriented, reliable byte stream service. That is, a TCP connection (three-way handshake) must be established between the client and server before data can be exchanged. It also provides functions such as timeout retransmission, discarding duplicate data, verifying data, and flow control to ensure that data can be transmitted from one end to the other.
UDP is a simple datagram – oriented transport layer protocol. It provides no reliability, just sending datagrams from the application to the IP layer, but with no guarantee that they will reach their destination. UDP does not need to establish a connection between the client and the server before transmitting data packets, and there is no timeout retransmission mechanism, so the transmission speed is very fast.
So it comes down to this:
TCP is connection-oriented, UDP is connectionless TCP data header with serial number, acknowledgement number, and so on. In contrast, UDP program structure is simpler. TCP is byte stream oriented, UDP is based on datagram TCP to ensure data correctness, UDP packet loss TCP to ensure data order, UDP does not guarantee you can see TCP is suitable for stable application scenarios, he will ensure the correctness and order of data, so the general web page, The interface access uses TCP transmission, so there is a three-way handshake to ensure the connection stability. UDP is a simple protocol that does not take into account packet loss, connection establishment, etc. The advantage is that data transmission is fast, so it is suitable for live broadcast, games and other scenes.
5. Several HTTP request methods are introduced in detail
There are four common ones:
GET gets the resource, no body, idempotent POST adds or modifies the resource, body PUT modifies the resource, body idempotent DELETE deletes the resource, idempotent
Common status code
It is mainly divided into five types: 1: indicates a temporary message, such as 100 (continue to send) 2: indicates a successful request, such as 200 (OK) 3: indicates a redirection, such as 304 (unchanged) 4: indicates some errors on the client, such as 403 (access forbidden) 5: indicates some errors on the server. For example, 500
6. How many HTTP requests can be sent over a TCP connection?
A TCP connection can send multiple HTTP requests if the connection is maintained.
7. Can HTTP requests sent in a TCP connection be sent together (for example, three requests sent together and three responses received together)?
A problem with HTTP/1.1 is that a single TCP connection can only handle one request at a time. This means that the life cycles of two requests cannot overlap. Any two HTTP requests cannot overlap from start to end in the same TCP connection.
8. Differences between Get and Post requests
Get request is more efficient than Post request. Post request requires the server to return 100 before sending data processing. Get request is directly through the URL. 2. The URL generated by GET can be bookmarked by the URL, but POST cannot. 3. Get request parameters will be fully retained in the browser history, while the parameters in POST will not be retained 5. The parameters passed in THE URL of GET request have a length limit of no more than 4K, while POST has no 6. For the data type of parameters, GET only accepts ASCII type, while POST has no restriction 7. Get is less secure than POST because parameters are directly exposed to the URL and therefore cannot be used to pass sensitive information 8. Get parameters are passed through the URL and POST is placed in the request body text 9. Get generates one TCP packet and POST generates two TCP packets
9. Http and Https
1. HTTPS requires a CA to apply for a certificate. Generally, there are few free certificates, so some fees are required. 2. HTTP is a hypertext transmission protocol, and information is transmitted in plain text. HTTPS is a secure SSL/TLS encryption transmission protocol. 3. HTTP and HTTPS use completely different connections and use different ports, the former 80 and the latter 443. 4. HTTP connections are simple and stateless; HTTPS is a network protocol that uses SSL, TLS, and HTTP to encrypt transmission and authenticate identity. It is more secure than HTTP.
10. What are HTTP long and short connections?
HTTP1.1 specifies the default HTTP persistent Connection (PERSISTENT connection), data transfer is completed to maintain the TCP connection constantly open (not send RST packets, not four times handshake), waiting for the same domain name to continue using this channel transfer data; The opposite is a short link.