Tcp:
is a long connection, after connecting with one client, the other client waits, to connect to the other one, it must gracefully disconnect the previous client connection.
Allow address reuse: Add before bind IP address and port, # server.setsockopt (socket). Sol_socket,socket. so_reuseaddr,1) # Allow (IP address and port) address reuse
Buffer
Input buffer #recv
Output Buffer #send
Sticky packets (two kinds of sticky-packet phenomena of TCP)
1 Send small data continuously, and the interval between each send is very short (output buffer: Two messages are glued together in the buffer)
The reason is that TCP has made an optimization algorithm (Nagle) in order to transfer efficiency, reducing the continuous packet delivery (since each message is wrapped, there will be two processes: 1 Pack 2 unpacking)
2 The first time the server sends the data than my client set the size of a receive message, then the reception is not complete, the second time to receive, will be the first time the remaining messages received
The root cause of the sticky packet is because: both parties do not know the size of the message sent by each other
Solution One:
Before sending a message, calculate the length of the message to be sent, then send the message length to the past, and the other person will give you a confirmation of the length of the message, and then modify the size of the received message based on the length of the message received.
This process is one more interaction.
network communication sticky packs and buffers