Note: the number (xx) before each question represents the frequency of the question. This computer network foundation is based on the 30+ questions and corresponding answers, reference links, etc. The content of the article is arranged by myself who got the Offer.

(3) Q: HTTP cache

HTTP caches are divided into strong caches and negotiated caches:

  • First verify that the strong Cache is available through cache-control. If the strong Cache is available, the Cache is read directly
  • If not, then enter the negotiation cache phase and make an HTTP request. The server checks whether the resource is up to date with if-modified-since and if-none-match conditional request fields in the request header:
    • If the resource was updated, the resource and the 200 status code are returned
    • If the resource is not updated, tell the browser to use the cache directly to get the resource

(5) Q: What are the common HTTP status codes and their usage scenarios?

  • 1xx: indicates that the protocol is in the intermediate state and further requests are required
  • 2xx: The request is successful
  • 3xx: indicates the redirection status. A request must be made again
  • 4xx: indicates that the request packet is incorrect
  • 5xx: The server is faulty

Common status code:

  • Switch the request protocol from HTTP to WebSocket
  • 200 The request succeeds with a response body
  • 301 Permanent redirection: cached
  • 302 Temporary redirection: will not be cached
  • 304 Negotiation cache hit
  • 403 The server is inaccessible
  • 404 Resource not found
  • 400 Request error
  • 500 A server error occurs
  • 503 Server Busy description

Do you know what the 302 status code is? What 302 scenarios have you encountered while browsing the web?

302 indicates temporary redirection. The resource cannot be accessed temporarily, but can be accessed after a period of time. Generally, when a user needs permission to access a resource on a website, the user needs to log in.

301 similar, will jump to a new site, but 301 represents the access to the address of the resource has been permanently removed, should not visit this address, search engine crawl will use the new address to replace the old. You can get the returned address in the location header of the returned response. The 301 scenario is as follows:

  • For example, go from Baidu.com to Baidu.com
  • Domain name changed

(2) Q: What are the common HTTP request methods, the differences and uses?

HTTP /1.1 specifies the following request methods:

  • GET: Obtain data generally
  • HEAD: Obtain the meta information of the resource
  • POST: Data is submitted
  • PUT: modifies data
  • DELETE: deletes data
  • CONNECT: Establishes a connection tunnel for the proxy server
  • OPTIONS: Lists the methods of requests that can be made to a resource, often used across domains
  • TRACE: TRACE the transmission path of the request-response

() Q: What do you know about computer networks

Application layer, presentation layer, session layer, transport layer, network layer, data link layer, physical layer

(3) Q: What is HTTPS? The specific process

HTTPS establishes a security layer between HTTP and TCP. In the communication between HTTP and TCP, HTTP must pass a security layer, encrypt the data packet, and then send the encrypted data packet to TCP. The corresponding TCP must decrypt the data packet before sending it to HTTP.

The browser transmits a client_random and a list of encryption methods, and the server sends a server_random, a list of encryption methods and a digital certificate (including the public key) to the browser. Then the browser validates the validity of the digital certificate. If the authentication is successful, a pre_random is generated. The server uses client_RANDOM, server_RANDOM, and pre_RANDOM to generate secret using public key encryption, and then the subsequent transmission uses the secret as the secret key to encrypt and decrypt the data.

Q: Three handshakes and four waves

Why a three-way handshake is needed: To confirm the sending and receiving capabilities of the other party.

Three-way handshake

The main process of the three-way handshake:

  • At first, both parties are in the CLOSED state, and then the server starts listening to a port and enters the LISTEN state
  • Then the client initiates the connection and sends SYN, and then changes itself to SYN-SENT, seq = x
  • When received, the server returns SYN SEq = y and ACK ACK = x + 1 (for SYN from the client) and becomes SYN-revd
  • Then the client sends ACK SEq = x + 1 and ACK = y + 1 to the server again, and it becomes EASTABLISHED. The server receives an ACK and becomes ESTABLISHED

SYN requires peer acknowledgment, so ACK serialization must be increased by one. If peer acknowledgment is required, it consumes the serialization of TCP packets

Why not twice?

The receiving capability of the client could not be confirmed.

If the client sends a SYN packet but the packet persists, TCP assumes that the packet is lost and retransmits the packet. The connection is established by a two-time handshake.

Wait until the client closes the connection. However, if the packet reaches the server, the server receives it, sends the corresponding data table, and establishes the link, but the client has closed the connection, so the link resource is wasted.

Why not four times?

Four or more times will do, but three times will do

Four times to wave

  • The client sends a FIN packet with seq = P and the status changes to FIN-wait-1
  • After receiving the packet, the server sends an ACK (ACK = p + 1) and enters the close-wait state
  • After receiving the packet, the client enters the FIN-wait-2 state
  • After a while, after the data processing is complete, the FIN and ACK are sent again. Seq = Q and ACK = P + 1 enter the last-ACK phase
  • After receiving the FIN, the client enters TIME_WAIT (waiting for 2MSL) and sends an ACK to the server. ACK = 1 + 1
  • After receiving the packet, the server enters the CLOSED state

At this time, the client needs to wait for two MSLS. If the client does not receive the resending request from the server, it indicates that THE ACK has arrived successfully and the client becomes CLOSED. Otherwise, the CLIENT resends THE ACK

Why you need to wait for 2MSL (Maximum Selifetime) :

If you do not wait, if the server has a lot of data packets to send to the client, and the client port is occupied by a new application, then the server will receive useless data packets, causing a packet chaos, so the safest way is to wait for the server to send all the data packets to die before starting the new application.

  • One MSL ensures that the last ACK message from the active close party in the four waves can finally reach the peer end
  • One MSL ensures that if the peer end does not receive an ACK, the FIN packet to be retransmitted can be received

Why four times instead of three?

** If it is three times, then the server’S ACK and FIN are combined in one wave, and the long delay may cause TCP to fail to reach the server with a FIN, which in turn causes the client to constantly resend the FIN

The resources

  • zhuanlan.zhihu.com/p/86426969
  • Juejin. Cn/post / 684490…

Q: What if you don’t want to disconnect the data during the interaction? How to maintain the connection?

In HTTP, the Connection field of the response body is specified as keep-alive

Do you know anything about TCP sliding Windows?

In a TCP connection, for both the sender and the receiver, TCP needs to put the sent data into the send cache and the received data into the receive cache. There is often a situation where the sender sends too much and the receiver cannot digest it. Therefore, flow control is required, that is, to control the sending of the sender by the size of the receiving cache. If the recipient’s receive cache is full, the recipient cannot send any more. The process of flow control needs to maintain a sending window at the sending end and a receiving window at the receiving end.

There are two types of TCP sliding Windows: sending window and receiving window.

The resources

  • Juejin. Im/post / 5 e527c…

Q: What’s the difference between WebSocket and Ajax

The nature of different

Ajax, which stands for asynchronous JavaScript and XML, is a Web development technique for creating interactive web applications

Websocket is a new PROTOCOL of HTML5, which realizes the real-time communication between browser and server

Different life cycles:

  • Websocket is a persistent connection and the session is always maintained
  • The Ajax send and receive will disconnect

Scope of application:

  • Websocket is used for real-time data exchange between the front and back ends
  • Ajax non-real-time

The sponsors:

  • The AJAX client initiates
  • The WebSocket server and client push each other

Do you know WebSocket?

Long polling and short polling. WebSocket is long polling.

Specific such as in a shopping mall, the inventory of goods may change, so the need to timely reflect to the user, so the client will keep the request, and then the server will keep to check the change, regardless of the change, are returned, this is a short polling.

In long polling, if there is no change, it does not return, but waits for change or timeout (usually ten seconds) before returning. If there is no return, the client does not need to send requests all the time, so the pressure on both sides is reduced.

Refer to the link

  • www.jianshu.com/p/3fc3646fa…

How does HTTP implement persistent connections? At what point does the time run out?

The HTTP1.0 protocol is supported by setting Connection: keep-alive in the header (request and response header), but it is disabled by default. Since HTTP1.1, connections are always persistent by default

  • HTTP usually has the HTTPD daemon, which can set keep-alive timeout to close a TCP connection if it is idle for longer than this time. It can also set a timeout in the HTTP header
  • TCP keep-alive contains three parameters that can be set in net.ipv4 of the system kernel: When tcp_KeepALIve_time is unused after the TCP connection, the probe packet will occur. If no ACK is received, the probe packet will be sent again every time until tcp_Keepalive_probes are sent. The link is discarded.
    • tcp_keepalive_intvl = 15
    • tcp_keepalive_probes = 5
    • tcp_keepalive_time = 1800

In fact, HTTP does not have long and short links, only TCP, TCP long links can reuse a TCP link to initiate multiple HTTP requests, which can reduce resource consumption, such as a request for HTML, may also need to request subsequent JS/CSS/ images, etc

Refer to the link

  • Blog.csdn.net/weixin_3767…
  • www.jianshu.com/p/3fc3646fa…

Q: What is the difference between the Fetch API and traditional Request

  • Fetch conforms to separation of concerns, uses promises, has a richer API, and supports Async/Await
  • The semantics are simple and more semantic
  • Isomorphic-fetch can be used to facilitate isomorphism

The resources

  • Github.com/camsong/blo…

(2) Q: What types of files can be sent by POST

  • Text, pictures, video, audio, etc
  • Text/image/audio/or application/json, etc

Q: How does TCP ensure effective transmission and congestion control?

  • TCP is a connection-oriented, reliable, transport-layer communication protocol

Reliability reflects in: state, can control

  • Stateful TCP determines which packets are sent, which packets are received, and which packets are not received by the receiver, ensuring that the packets arrive in sequence and no errors are allowed
  • Controllable means that if there is a packet loss or a bad network condition, it will redirect its behavior, slow down the transmission or resend the transmission

So it ensures that the packets are transmitted efficiently.

Congestion control principle

The reason is that it is possible that the whole network environment is particularly bad and easy to lose packets, so the sender should pay attention.

There are three main methods:

  • Slow start threshold + Congestion avoidance
  • The fast retransmission
  • The quick reply

Slow start threshold + Congestion avoidance

For congestion control, TCP maintains two core states:

  • Congestion Window (CWND)
  • Slow Start Threshold (SSthresh)

Use the congestion window at the sender to control the size of the send window.

And adopt a more conservative to adapting to the network slow start algorithm, at the start of transmission for a period of time, the sender and the receiver will first through the three-way handshake to establish a connection, determine the respective receiving window size, and then initializes the congestion window, then each after a RTT (sending and receiving time delay), double the congestion window size, until you reach the slow start threshold.

And then you start to do congestion avoidance, and the way you do congestion avoidance is you double the congestion window for each round of RTT, and now you add one for each round.

The fast retransmission

In the process of TCP transmission, if packet loss occurs, the receiver will send the previous repeated ACK. For example, if the fifth packet is lost and the sixth and seventh packets are reached, the receiver will send the fourth ACK for the fifth, sixth and seventh packets. At this time, the sender receives three repeated ACK packets, realizes the packet loss, and immediately retransmits. Without waiting for the RTO

Optional retransmission: The SACK attribute is added to the packet header, and the left edge and right edge are used to indicate the incoming packets, and then the missing packets are retransmitted

Fast recovery

If the sender receives three repeated ACKS, finds the packet loss, and thinks that the current network condition has entered the congestion state, then it will enter the rapid recovery phase:

  • The congestion threshold is reduced to half of the congestion window
  • Then the congestion window size changes to the congestion threshold
  • Then the congestion window is linearly increased to adapt to the network condition

Q: What does OPTION do? What’s an example of using OPTION?

The object is to send a probe request to determine what constraints a request for a target address must have, and then send the actual request based on those constraints.

For example, precheck for cross-domain resources is sent first using the OPTIONS method of HTTP. Used to process cross-domain requests

Q: What about HTTP? Which layer of protocol? (Application layer)

  • Flexible and extensible, in addition to space delimited words, newline delimited fields, other restrictions, not only can transfer text, but also images, videos and other arbitrary resources
  • Reliable transport, based on TCP/IP so inherits this feature
  • Request-answer, back and forth
  • Stateless, each HTTP request is independent, irrelevant, and does not need to save context information by default

Disadvantages:

  • Plaintext transmission is not secure
  • When a TCP link is reused, congestion occurs
  • Stateless In a persistent connection scenario, you need to save a lot of context to avoid transferring a lot of duplicate information

Q: The OSI seven-tier model and TCP/IP four-tier model

  • The application layer
  • The presentation layer
  • The session layer
  • The transport layer
  • The network layer
  • Data link layer
  • The physical layer

TCP/IP has four layers:

  • Application layer: application layer, presentation layer, and session layer: HTTP
  • Transport layer: Transport layer: TCP/UDP
  • Network: Network: IP
  • Data link layer: data link layer and physical layer

(3) Q: How is TCP reliable? Why is UDP not reliable?

  • TCP is a connection-oriented, reliable, transport-layer communication protocol
  • UDP is a connectionless transport layer communication protocol that inherits IP features and is based on datagram

Why is TCP reliable? The reliability of TCP is reflected in stateful and control

  • It keeps track of exactly which data was sent, which data was received, which data was not received, and ensures that the packets arrive in order, without any error, which is stateful
  • When TCP realizes that a packet is lost or that the network environment is bad, it can adjust its behavior to the situation, controlling its own transmission speed or resend, which is controllable

UDP, on the other hand, is stateless and uncontrollable

HTTP 2 improvement

Improved performance:

  • The head of compression
  • Multichannel multiplexing
  • Server Push

The resources

  • Juejin. Im/post / 5 d032b…

❤️ Thanks for your support

If you like it, don’t forget to share it, like it and watch it again.