[Resolve] Usually only one use per socket address is allowed

Source: Internet
Author: User
Tags server port

When we do socket development, we often encounter this error: usually each socket address (Protocol/network address/port) only allowed to use once

The error indication is clear: the communication port is occupied, causing the communication to fail.

But why is the port occupied? What port is occupied.

Here is a major premise: Your program has not specified the socket communication port.

If specified, the workaround is simple, and each communication completes a manual release . The next communication is to re-establish the connection.

If not specified, describe the following points (perhaps one of the points you hit):

1, your server to open the number of ports too small;

2, the connection release waiting time is too long;

3, your socket communication volume is too large.

The above causes your server port to be occupied, the next communication no idle port is available, the program throws "usually each socket address (Protocol/network address/port) only allowed to use once" exception.


Reason found, solve it is simple, for 1, 22 points, we modify the server configuration on the line.

If your server is windows2003 or XP, the default port is only open to 5000, and the timeout wait defaults to 240 seconds (here's an official note: http://msdn.microsoft.com/zh-cn/library/aa560610 v= bts.10). aspx, we simply open the server port completely and adjust the timeout according to our own situation.

Specific actions:

1, open the registry (run the command: regedit)

2, locate the Registry node: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

3, add 2 items (if already exist on the modified item value), the value corresponds to the 10 binary digits

maxuserport=65534 (number of ports set to maximum)

Tcptimedwaitdelay=5 (timeout Wait is 5 seconds, depending on individual needs)

4, restart the server


Get.


Author: Zhu Huazhen

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.