TCP/IP port depletion

Source: Internet
Author: User

Http://msdn.microsoft.com/zh-cn/library/aa560610 (V = bts.10). aspx

Content of this article: 1. view port usage; 2. Problems Caused by port depletion; 3. Solutions

When the client starts a TCP/IP socket connection to the server, the client usually connects to a specific port on the server and requests the server to respond through a temporary (or temporary) TCP or UDP port. In Windows Server 2003 and Windows XP, the default range of temporary ports used by client applications is 1025 to 5000. In some cases, the available ports in the default range may be exhausted.

The symptoms of TCP/IP port depletion vary with client applications, but they usually show network connection failure errors. To determine whether a network connection failure is caused by the exhaustion of TCP/IP ports, perform the following steps on the client computer:
  1. On a computer running Windows XP or Windows Server 2003, click Start"And then click "run"And then type
    CMD, Click OK"Open command prompt.
  2. Perform one of the following operations:
    • Enter the following command in the command prompt on a Windows XP or Windows Server 2003 computer to display the active connection used by the TCP/IP protocol on this computer:

    Netstat-n
    This will list the TCP/IP addresses bound to the client computer and the ports used to communicate with the remote server. If the listed ports use all available ports, the TCP/IP port is exhausted.

    • Enter the following command in the command prompt of a Windows Server 2003-based client computer to display the active connections used by the TCP/IP protocol:
      netstat -b
Problems related to TCP/IP port depletion

When a client application tries to connect to the server using a TCP/IP socket, the following situations may occur:

System. net. webexception: The underlying connection was closed: An Unexpected error occurred on a send.

-Or-

Unable to connect to the remote server
System. net. sockets. socketexception: Only one usage of each socket address (Protocol/network address/port) is normally permitted.

Cause

If the client computer has a large number of TCIP/IP socket connections, the client computer may be exhausted by TCP/IP ports. This situation may occur if multiple client applications are establishing a connection.

If all the available temporary ports are allocated to the client application, the client will be exhausted by the TCP/IP Port. When the TCP/IP Port is exhausted, the client port cannot be reserved, and the client application that tries to connect to the server through the TCP/IP socket also fails.

Under high load conditions, TCP/IP port depletion is more likely than normal load.

Solution

Perform the following steps to avoid TCP/IP port depletion and related problems:

  1. Verify that the client application does not generate too many TCP/IP socket connections. This can be checked using the method mentioned above, that is, running on Windows Server 2003 and Windows XP
    Netstat-nOr run on Windows Server 2003 and 2008.Netstat-B.

    If a client application uses a large number of TCP/IP socket connections, you should consider re-designing the client application to more effectively use TCP/IP socket connections.
    If a large number of client applications need to start a Known Number of TCP/IP socket connections, but there are not enough temporary ports available to meet the connection request, you need to modify the following registry.

  2. Increase the upper limit of the temporary port dynamically allocated to the client's TCP/IP socket connection.
  • Start Registry Editor, browse to the registry, and click the following registry key.
    HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters
  • In "edit"Click "new" in the menu", "DWORD Value"And then add the following registry values to increase the number of temporary ports that can be dynamically allocated to the client:

    Value Name

    Maxuserport

    Value Data

    <Enter a decimal value between 5000 and 65534 here>

  • Close Registry Editor.
    Note:
    The change takes effect only after the computer is restarted.

Reduce the timeout value of client TCP/IP socket connection (default value: 240 seconds)

  1. Start Registry Editor.
  2. In the registry, browse to and click the following registry key.
    HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters
  3. In "edit"Click "new" in the menu", "DWORD Value"And then add the following registry values to shorten the time for the connection to be In the time_wait state when the connection is closed. When the connection is in the time_wait status, the socket pair cannot be used again:

    Value Name

    Tcptimedwaitdelay

    Value Data

    <Enter a decimal value between 30 and 240.>

  4. Close Registry Editor.
    Note:
    The change takes effect only after the computer is restarted.

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.