Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 May : Best way to shut down server app
| Subject: | Best way to shut down server app |
| Posted by: | "John Carlyle-Clarke" (jpcc@removethis.bigfoot.com) |
| Date: | 19 May 2006 07:05:30 |
Using Indy Sockets 10.1.5, TIdTCPServer.
I'm looking for the best way to close down connections and the
application in an orderly way.
The application has a main window which contains the TCP Server
component. When a connection comes in, a new form is created for each
connection, which holds a reference to the context. Similarly an
object held by the context references the form. Incoming lines are
displayed on the form, and the form can send lines back to the remote
host.
Situation 1
-----------
The user closes the form for a connection. Currently I call:
FContext.Connection.IOHandler.Close;
.. on the context associated with the window. I'm doing this from the
main GUI thread. Is this acceptable?
Situation 2
-----------
The user closes the main form. If I just set
IdTCPServer1.Active := false;
then will each connection raise a Disconnect event? If so, will this
happen synchronously or asynchronously? If the latter, how do I
reliably wait for this to complete?
Alternatively, I could, from the GUI thread, call
FContext.Connection.IOHandler.Close;
on each connection. Again, will these calls be sync or asyc? How can
I be sure that all connections are closed before allowing the
application to exit?
I seem to get some access violations sometimes on shutdown when closing
the main form - I can't see where they are occuring - and I suspect
it's to do with this design issue.
What is the best way to handle this?
Thanks in advance!