1. Talk about your understanding of TCP three-way handshake and four-way wave

Http2 differs from http1

  1. Binary protocol

The HTTP/1.1 header is definitely text (ASCII encoded), and the data body can be either text or binary. HTTP/2 is a completely binary protocol. Headers and data bodies are binary and collectively referred to as “frames” : header and data frames.

One advantage of the binary protocol is that additional frames can be defined. HTTP/2 defines nearly ten frames, setting the stage for future advanced applications. If you do this with text, parsing the data becomes cumbersome, while binary parsing is much more convenient.

  1. Header compression

    The HTTP protocol has no state, and all information must be attached to each request. HTTP/2 optimizes this by introducing header compression. On the one hand, the header information is compressed using gzip or COMPRESS and then sent. On the other hand, both the client and the server maintain a header table where all fields are stored, generating an index number, and then not sending the same field, but only the index number, which increases speed.

  2. The data flow

    Because HTTP/2 packets are sent out of order, successive packets within the same connection may be different responses.

    HTTP/2 multiplexes TCP connections so that both the client and the browser can send multiple requests or responses at the same time in a single connection without having to follow the sequence, thus avoiding “queue congestion”.

  3. Bidirectional communication

    HTTP/2 allows the server to send resources to clients unsolicited

    What front-end applications are available on HTTP2

3. After the connection between A and B is normal, B suddenly restarts. What is the TCP status of A

If A and B have established A normal connection, but have never sent data to each other, then B suddenly restarts and asks A what status of TCP is in at this time? How do I eliminate this state in the server program?

Juejin. Cn/post / 684490…

4. What is the difference between TCP and UDP?

UDP

The User Datagram Protocol (UDP) is a connectionless Protocol that provides unreliable User Datagram services.

The UDP header contains only four fields: source port, destination port, UDP length, and UDP parity code. Each field contains 16 bits, that is, two bytes.

  1. Connectionless UDP does not require a three-way handshake to establish a connection as TCP does before sending data. UDP sends data directly. UDP is only a porter of data packets and does not split or splice data packets.
  2. Unreliable reliability is reflected in the first connection, communication does not need to establish a connection, want to send, such a situation is certainly not reliable; They send the data they receive without backing it up and without caring whether the other party has received the data correctly. Moreover, the network environment is up and down, but UDP always sends data at a constant speed because it has no congestion control. The transmission rate will not be adjusted even if the network condition is not good. The disadvantage of this implementation is that packet loss may occur when the network condition is not good, but the advantage is also obvious. In some scenarios requiring high real-time performance (such as live broadcast and teleconference), UDP is used instead of TCP.
  3. Unicast, multicast, broadcast function. Since UDP does not establish connections, it can transmit data to anyone, not only in one-to-one mode, but also in one-to-many, many-to-many, and many-to-one modes.
  4. UDP is a UDP packet sent by the sender to the application program. After the header is added, the packet is sent to the IP layer (UDP packets sent by the application layer are neither merged nor split, but the boundaries of the packets are preserved).
  5. Low header overhead and high data transmission Efficiency UDP has a low header overhead of only 8 bytes and is efficient in transmitting data packets (UDP is frequently used in real-time scenarios such as live broadcast, conference call, and media transmission).
TCP

Transmission Control Protocol (TCP) is a connection-oriented and reliable Transmission layer communication Protocol based on byte stream.

  1. Source port and destination port The port number of the sender process and the port number of the data receiver (0-65535).

  2. Serial number is mainly to solve the problem of disorder (good number to know which to come first, which to arrive later);

  3. The packet sent by the confirmation serial number should have confirmation, so that you can know whether the other party received it. If not, you should send it again. This solves the problem of not losing packets.

  4. Status bits: SYN initiates a connection, ACK replies, RST reconnects, and FIN terminates a connection. TCP is connection-oriented and requires both parties to maintain the connection state. Packets in these status bits cause state changes for both parties.

  5. Window size To control TCP traffic, each communication party needs to declare a window to identify its current processing capability

5. Before answering this question, consider why and under what conditions TCP packets are lost.

If server A sends data to server B too often, server B cannot process the data. As A result, data packets are lost.

(The cause may be program logic problems, multithreaded synchronization problems, buffer overflow problems)

If server A does not control the transmission frequency, or the data is retransmitted, then server B will receive less data. You lose data

6. How do I solve the problem of TCP packet loss

To ensure TCP packet loss. The TCP protocol has the following provisions:

  1. Data fragmentation: The sending end fragments data, and the receiving end reorganizes data. TCP determines the fragment size and controls the fragment and reassembly

  2. Acknowledgement on arrival: When receiving fragment data, the receiving end sends an acknowledgement to the sending end based on the fragment data sequence number

  3. Timeout retransmission: The sender sets a timeout timer when sending fragments. If no acknowledgement is received after the timer expires, the fragment data is resended

  4. Sliding window: Each end of the TCP connection has a fixed buffer size. The receiving end only allows the other end to send data that can be accepted by the receiving end buffer. Based on sliding window, TCP provides flow control to prevent the buffer overflow of the fast host from the slow host

  5. Disordering processing: TCP fragments transmitted as IP datagrams may be disordered upon arrival. TCP reorders the received data and sends the received data to the application layer in the correct sequence.

  6. Repeat processing: TCP fragments transmitted as IP datagrams are duplicated. The TCP receiver must discard the duplicated data.

  7. Data checksum: TCP maintains the checksum of its header and data, an end-to-end checksum, to detect any changes in the data during transmission. If a fragment is received or an error occurs, TCP discards the fragment. As a result, the peer end times out and resends the fragment

7. What do you know about HTTP response codes and their meanings?

1XX (Interim response)

100: The requester should continue to make requests.

101(Switching protocol) The requester has asked the server to switch protocol and the server has confirmed and is ready to switch.

2 xx (successful)

200: The right request returns the right result

201: indicates that the resource is correctly created. For example, if we create a user with the correct username and password, we can return 201.

202: The request is correct, but the result is being processed, at which point the client can continue the request through mechanisms such as polling.

3xx(Redirected)

300: Request successful, but results in multiple choices.

301: The request succeeds, but the resource is permanently transferred.

303: Use GET to access the new address to GET the resource.

304: The requested resource has not been modified

4xx(Request error)

400: Request error, such as unequal header.

401: No certification information provided. Request without Token, etc.

402: Indicates the status code reserved for future use.

403: The requested resource is not accessible. That means no access.

404: The requested content does not exist.

5xx(Server error)

500: Server error.

501: The request has not been fulfilled.

Principle 8. SSL

www.ruanyifeng.com/blog/2014/0…

9. This section describes HTTPS man-in-the-middle attacks

Juejin. Cn/post / 684490…

10. During the HTTPS handshake, the client verifies the validity of the certificate

www.jianshu.com/p/94dd4b197…