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