network communication sticky packs and buffers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.