Is there a limit on the number of bytes received by a socket Recv? Setsockopt sets the socket status

Source: Internet
Author: User

The answer is: yes. It is about 5-15 kb. I don't know what the default value is. I tested 16371 bytes. Win7 x64.

You can use setsockopt to set the recvbuf or sndbuf size. However, we recommend that you set the number of bytes received each time to a certain range, such as 5 kb. Because even if it is set, it is still possible to accept a small number of bytes.

The more important thing about socket usage is how to process data. InvolvedAlgorithm.

For example, if you want to accept a large buffer, you can set enough buffer, and then accept it. If you accept less buffer, you can continue to accept it, but accept it at the buffer + bufferoffset position, bufferoffset increases by the number of accepted bytes. Until the total number of accepted items is sufficient.

 

In addition, a socket Send package may be appended to the previous socket Send package. In this way, the User-Defined header information in your send data is not the first byte and must be processed.

The safer method is to accept the buffer to process one byte... It may be inefficient ..

 

Refer:

Setsockopt sets the socket status

Http://baike.baidu.com/view/569217.htm

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.