gogoWebsite

The difference between using connect to establish a connection and a normal udp connection

Updated to 2 days ago

There is an essential difference between the connect operation in UDP and the connect operation in TCP. Calling connect in TCP will cause three handshakes, and the client establishes a connection with the server. Calling the connect kernel in UDP only records the peer ip&port

UDP connection established using connect has two advantages over ordinary UDP connections:

1: Improve the transmission efficiency

1. Send two packets on a normal udp connection, and the kernel operation is as follows:

a) Establish a connection; b) Send a message; c) Disconnect; d) Establish a connection; e) Send a second message; f) Disconnect

UDP sends two packets, and the kernel operation is as follows:

a) Establish a connection; b) Send the first message; c) Send the second message; d) Disconnect

2: System stability can be increased in high concurrency services

    Suppose A communicates with server B, C through non-connect UDP. B, C provides the same services. For load balancing, we let A communicate with B, C alternately. A communicates with B and B IPa:PORTa <----> IPb:PORTb     A communicates with C IPa:PORTa' <---->IPc:PORTc
Assuming that PORTa and PORTa' are the same (this will happen in large concurrency situations), then it is possible that A is waiting for B's message, but receives C's message, resulting in a report receiving error. The solution is to use the connect UDP communication method. Create two udp in A, and then connect to B and C respectively.