PRB: Winsock Control Generates Error 10048 - Address in UseLast reviewed: September 9, 1997Article ID: Q173619 |
The information in this article applies to:
SYMPTOMSThe Winsock control will get an error after a Connect method is called if the same local port has been used within the past four minutes.
CAUSEThe Windows socket control does not have the ability to set the socket option SO_REUSEADDR. This option allows the socket to be bound to an address that is already in use. When you close the handle to a socket, some additional negotiation goes on between the client and the server. The socket will wait for up to two times the maximum time that windows would wait to receive an acknowledgement from the other end of the socket that closed the port. By default, this option is set to two minutes. Therefore, Windows may wait up to four minutes before the port is actually released. This makes that specific port unavailable until it is actually released.
RESOLUTIONThe only workaround is to not use a specific local port. If you set the LocalPort property to Zero, Winsock will pick a random local port for you and use it until a Close method is called on the WinSock Control.
STATUSThis behavior is by design.
MORE INFORMATIONSetting the LocalPort property of the socket to Zero, will cause Windows to pick a random port. To do this, place the following code just before the line that does the connect:
Winsock1.LocalPort = 0 Winsock1.Connect Steps to Reproduce BehaviorThe following sample demonstrates how to reproduce the issue and how to work around it. In the code "myserver" indicates any Windows NT Server running Simple TCP/IP Services, which includes an Echo server on Port 7.
Winsock1.LocalPort = 2500to:
Winsock1.LocalPort = 0and perform steps 4 through 6 several times. You should not get any errors. Keywords : vb5all kberrmsg Version : WINDOWS:5.0 Platform : WINDOWS Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |