Windows Socket port modification)

Source: Internet
Author: User
In TCP applications, the communication between the two parties is connection-oriented, and multiple connections on the same computer must be different from each other. In the TCP protocol, [Source IP + Source Port + Destination IP + Destination Port] is used to differentiate two different connections. That is to say, as long as one of the four parameters is different, the two connections are different. On the BBS, we can see that many people simply think that the number of ports that can be used is a limiting factor for establishing connections. In fact, this is incorrect. The connection restrictions between the server and client software are different. Let's take a look at them separately.

In the server software, there is a port used to listen for accepting client connections. From the client perspective, it is called the destination port, the IP addresses (source IP addresses) connecting different computers to the port on the server must be different, while two different connections on the same computer use different ports (source ports) to connect to the server. No matter how many clients are connected, the server uses only one port, and the server identifies different customers through the source IP address and source port. Someone will ask if the server can accept countless connections. Theoretically, this is not the case, because each connection created by the system requires a certain amount of paging memory and non-page buffer pool memory, and the memory resources of the computer cannot be infinite, therefore, the server cannot accept numerous connections. When the number of connections reaches a certain number, a 10055 error may occur, indicating that the memory resources are insufficient. Write another article when the specific restrictions on memory resources and acceptable connections are empty.

Different from the server, each client initiates a connection using a random port called a temporary port. Because the port range is 0 ~ 65535, and below 1024 is the port reserved by the system, so theoretically there can be up to 65535-1024 ports available, however, in actual tests, the error 5000 may occur if 10048 connections fail to be reached. In fact, this is because the windows system has set restrictions. In Windows, the default temporary port range is 1024 ~ 5000, that is, there are only 3977 available ports. If there are more ports, the error 10048 will occur. Of course, there may be errors of insufficient memory resources before these errors are reached, because the client and server are also subject to memory resource restrictions. However, this is a problem with hardware resources. Let's take a look at how to adjust the limitation of the temporary port range. Windows provides a way to solve this problem. Create a maxuserport dubyte value under the Registry HKLM \ System \ CurrentControlSet \ Services \ Tcpip \ Parameters and specify the maximum number of temporary ports, for example, if it is changed to 10000, the available temporary port range is 1024 ~ 10000. This parameter can be changed to a maximum of 65534.

The modification to maxuserport seems to take effect only after the computer is restarted. After I change it to 50000, 5000 errors may occur when I initiate 10048 connections to the server. After the restart, nearly 20 thousand connections are connected, and no error 10048 is displayed.

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.