To listen for connections on any suitable IPv4 interface, specify
the special dotted-quad address "0.0.0.0". You can accept
connections from clients using either IPv4 or IPv6 on the same socket by
specifying the special IPv6 address "::0", however this is only
supported on Windows 7 and Windows Server 2008 R2 or later platforms. If
no local address is specified, then the server will only listen for
connections from clients using IPv4. This behavior is by design for
backwards compatibility with systems that do not have an IPv6 TCP/IP
stack installed.
If the INET_OPTION_REUSEADDRESS option is not specified, an error may
be returned if a listening socket was recently created for the same
local address and port number. By default, once a listening socket is
closed there is a period of time that all applications must wait
before the address can be reused (this is called the TIME_WAIT
state). The actual amount of time depends on the operating system and
configuration parameters, but is typically two to four minutes.
Specifying this option enables an application to immediately re-use a
local address and port number that was previously in use. Note that
this does not permit more than one server to bind to the same
address.
If the INET_OPTION_EXCLUSIVE option is specified, the local address
and port number cannot be used by another process until the listening
socket is closed. This can prevent another application from forcibly
binding to the same listening address as your server. This option can
be useful in determining whether or not another process is already
bound to the address you wish to use, but it may also prevent your
server application from restarting immediately, regardless if the
INET_OPTION_REUSEADDRESS option has also been specified.
If an IPv6 address is specified as the local address, the system
must have an IPv6 stack installed and configured, otherwise the
method will fail.
The use of Windows event notification messages has been deprecated
and may be unavailable in future releases. It was designed for use in
legacy single-threaded applications and requires the application to
have a message pump to process event messages. It should not be used
with applications which are designed to execute as a service or those
which do not have a graphical user interface.
To prevent this method from blocking the main user interface thread,
the application should create a background worker thread and establish
a connection by calling Listen in that thread. If
the application requires multiple simultaneous connections, it is
recommended you create a worker thread to accept each client session.
When a message is posted to the notification window, the low word
of the lParam parameter contains the event identifier. The
high word of lParam contains the low word of the error code,
if an error has occurred. The wParam parameter contains the
socket handle. One or more of the following event identifiers may be
sent:
| Constant |
Description |
| INET_EVENT_ACCEPT |
An incoming client connection is pending. The connection will
be assigned to a new socket. This event is only generated if the
socket is in asynchronous mode. |
To cancel asynchronous notification and return the socket to a
blocking mode, use the DisableEvents method.