Premise: The core mechanism to ensure the reliability of messages – timeout, retransmission, confirmation, although TCP mechanism can ensure the reliable transmission of messages, but this is based on C/S or B/S communication, if the A-server-B end needs to ensure the reliable transmission of messages in the application layer.

Scenario: Client A sends A message to client B (clients A, B, and server S). Assume that client B is online. 1 2, S according to the message id through online users table to find the client B IP and port, and to send A message to 3 B, B messages are received and return to the server S have received the confirmation message, 4 S give A received message confirmation B (if you don't to confirm the B S, B will timeout retransmission) to send A B, S confirmation messages are received 6. A sends A one-day confirmation message to S (if A does not send A confirmation message to S,S thinks that A has not received it, and timeout retransmission will be triggered)Copy the code