The Stop method instructs the server to stop accepting
client connections, disconnects all active client connections and
terminates the thread that is managing the server session. This method
will block waiting for the clients to disconnect and the server thread
to terminate. Once the server has stopped, the OnStop event
will fire.
Clients that are disconnected using the Stop method are
terminated immediately and will not generate an OnDisconnect
event. If your application is using this event to perform some cleanup
on a per-client basis, then you should shutdown the server by first
calling the Suspend method to prevent new connections from
being accepted and terminate all active client sessions. The
OnDisconnect event will fire for each client as it disconnects
from the server, and when the last client has disconnected, the
OnIdle event will fire. You can then call the Stop
method to complete the shutdown of the server.
After the server has been stopped, the closed 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, set the
ReuseAddress property to a value of True.