The InetServerStop function signals the server to stop
accepting client connections, disconnects all active client
connections and terminates the thread that is managing the server
session. The socket handle is no longer valid after the server has
been stopped and should no longer be used. Note that it is possible
that the actual handle value may be re-used at a later point when a
new server is started. An application should always consider the
socket handle to be opaque and never depend on it being a specific
value.
If this function is called when there is one or more clients
connected to the server, it will signal each client thread to
terminate and then wait for
the server thread to terminate. As the client sessions are terminated,
the event handler will not be invoked. If you wish
to ensure that all clients are disconnected normally before stopping the
server, call the InetServerSuspendEx function with the
INET_SUSPEND_DISCONNECT option and then stop the server after the
last client has disconnected.
Because the InetServerStop function waits for the server
thread to terminate, this function may cause your application to
block. If this is not desirable, use the InetServerStopEx
function which can perform the shutdown sequence asynchronously.
After the server thread has been terminated, the listening socket
will go into a TIME-WAIT state which prevents an application from
reusing the same address and port number bound to that socket for a
brief period of time, typically two to four minutes. This is normal
behavior designed to prevent delayed or misrouted packets of data
from being read by a subsequent connection. To immediately start a
new server using the same local address and port number, the option
INET_OPTION_REUSEADDRESS must be specified when calling the
InetServerStart function.