|Subject:||How do I gracefully close down a connection?|
|Posted by:||Alan McFarlane (alan.mcfarla…@gmail.com)|
|Date:||Fri, 24 Mar 2006|
I have a small CmdTCPServer which has up to 100 clients connected at any
Now, occasionally, I need to shut the server down, but if I've got any
clients connected, it really pi**es them off.
Ideally, what I'd like to is, when I select "Stop Server" my
application, it should a) shut the server immediatelly if there are no
clients connected, or b) set a flag 'FStopping' that I can examine in
the OnConnect event. If it's set, I can just send a "sorry, server going
offline" reply and disconnect.
The problem, is, whilst that part appears to work, whenever a client
disconnects, in the OnDisconnect event, I check the current client
count. If it's zero, I set the servers 'Active' property to false. This
always seems lock the application. :(
Any suggestions as to how this can be corrected, gratefully recieved.