1. TCP three-way handshake

The purpose of a handshake is to establish a connection. In TCP/IP, TCP provides reliable connection services. A three-way handshake is used to establish a connection

The TCP three-way handshake process is as follows:

  • First handshake: When establishing a connection, the client sends a SYN packet (SYN = J) to the server and enters the SYN_SEND state, waiting for confirmation from the server.
  • Second handshake: After receiving a SYN packet, the server must acknowledge the client’s SYN (ACK = J +1) and send a SYN packet (ACK = K). In this case, the server enters the SYN_RECV state.
  • Third handshake: After receiving the SYN+ACK packet from the server, the client sends an ACK packet (ACK = K +1) to the server. After the packet is sent, the client and the server enter the ESTABLISHED state to complete the three-way handshake.

2. TCP four waves

The wave is used to terminate the connection, and TCP uses four waves to release the connection

The TCP wave four flow is as follows:

  • First wave: The client sends a FIN to stop data transmission from the client to the server, and the client enters the FIN_WAIT_1 state.
  • Second wave: After receiving a FIN, the server sends an ACK to the client. The ACK sequence number is +1 (the same as that for SYN, one FIN occupies the same sequence number). The server enters CLOSE_WAIT state.
  • Third wave: The server sends a FIN to disable data transfer from the server to the client, and the server enters the LAST_ACK state.
  • Fourth wave: After receiving the FIN, the client enters the TIME_WAIT state and sends an ACK to the server to confirm that the FIN number is +1. The server enters the CLOSED state and waves four times.

Why does it take four waves to disconnect

  • Both the sender and receiver require FIN packets and ACK packets

3. Why is there a TIME_WAIT state

  • Ensure that there is enough time for the ACk packet to be received
  • Avoid confusion between old and new connections

4. Cause of the large number of CLOSE_WAIT status on the server

The other party closed the socket connection. We were too busy reading or writing to close the connection in time

Solutions:

  • Review code, especially code that frees resources
  • Check the configuration, especially the thread configuration for handling requests

5. TCP sliding window

6. The UDP characteristics

1. Non-connection oriented 2. Does not maintain connection status and supports simultaneous transmission of the same message to multiple clients 3. The packet header is only 8 bytes and the extra overhead is low 4. Throughput is limited only by the data generation rate, transmission rate, and machine performance 5. Best effort delivery, no guarantee of reliable delivery, no need to maintain complex link state table 6. Packet oriented, the packet information submitted by the application program is not split or merged

7. Main features of HTTP

  • Client/server mode is supported
  • Simple and quick
  • flexible
  • There is no connection
  • stateless

8. Differences between GET and POST requests

  • HTTP packet layer: GET puts the request information in the URL, and POST puts the request information in the message
  • Database level: GET complies with idempotency and security, but POST does not
  • Other layers: GET can be cached and stored, but POST can’t