Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Oct : Re: Closing down a Indy 9/10 IdTCPServer
| Subject: | Re: Closing down a Indy 9/10 IdTCPServer |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Fri, 20 Oct 2006 10:56:40 |
"Matt Mazanec" <tsusai@gmail.com> wrote in message
news:4538cd0e$1@newsgroups.borland.com...
> I'm looking for a proper way to do the shutdown by killing all
> connections nicely (I have disconnection methods for the clients).
TIdTCPCServer already does that for you. When setting the Active property
to False, it disconnects all active clients, and then waits for their
cooresponding threads to terminate themselves.
> well I know I cannot do just an active := false;
Yes, you can.
> because all my clients time out and exceptions are raised that I cannot
control.
That is perfectly normal. Indy makes heavy use of exceptions. You will get
an exception in your OnExecute code when the client is closed by the server.
Just ignore it. Let the exception pass back into the TIdTCServer and it
will be handled.
> Indy 9 code (I know i got the exception wrong (this is older code as
> i do not have fixed on hand) but I hope you understand what I am
> getting at.
You do not need any of that code in the first place.
> Not sure if it works with clients that login in the meantime though....
> thats what I am scared of.
Set the server's MaxConnections property to 1 when shutting down. Or else
disconnect the client in the OnConnect event during shutdown.
> TIdPeerThread(List.Items[idx]).Connection.Disconnect;
In Indy 9, use DisconnectSocket() instead of Disconnect() when closing a
socket from another thread.
Gambit