Board index » delphi » Indy TCP Client / Server question

Indy TCP Client / Server question

I have a connection between an IdTCPServer and IdTCPClient.  My problem is
how to shut down the server without crashing the client.

I have tried calling  .connection.disconnect for all the connections on the
server but I get an exception at the client side (10053 ) followed by
'connection closed gracefully' if I try to read/write the connection again.

I have an OnDisconnected event handler in the client side, but it doesn't
fire when I call disconnect at the server.

How do you shut down the server in a way that doesn't upset the client(s).

Thanks for any tips,

Jim

 

Re:Indy TCP Client / Server question


Quote

> How do you shut down the server in a way that doesn't upset the
client(s).

Wrong question.  You should be asking 'How can I design my client so
that it does not crash no matter what happens on the network or
server?'

Rgds,
Martin

Re:Indy TCP Client / Server question


Well, I suspect its a bit of both.

1)    If the server has to shut down while it has active clients, what steps
should the server take to shut down?

2)   How do I design the client side so that it does not crash when the
connection is terminated by the server closing down?

In either case, do you have the answer?

Thanks
Jim

Quote
"Martin James" <mjames_fal...@dial.pipex.com> wrote in message

news:3e8ed50b@newsgroups.borland.com...
Quote

> > How do you shut down the server in a way that doesn't upset the
> client(s).

> Wrong question.  You should be asking 'How can I design my client so
> that it does not crash no matter what happens on the network or
> server?'

> Rgds,
> Martin

Re:Indy TCP Client / Server question


Quote
Jimmy <JimmyatnospamKe...@hotmail.com> wrote in message

news:3e8f0844@newsgroups.borland.com...

Quote
> Well, I suspect its a bit of both.

Well, it's sorta accepted that servers and clients should not crash
because of something the other end has or has not done.  Networks are
fickle and malicious.  They will do anything they can to bring down
your app.  We must not let them.  Join the Jihad against the religion
of the routers.

Quote

> 1)    If the server has to shut down while it has active clients,
what steps
> should the server take to shut down?

In general, it should bar the acceptance of  new connections,
disconnect all clients, terminate & free all their threads, sockets &
other resources & shut down the listener thread, (not neessarily in
this order).  AFAIK, this happens in Indy when you set 'active' to
false. There are persistent rumours, though, that say there are some
problems with Indy 9 if any lengthy operations are carried out in the
onDisconnect handler.  I've never used this handler, but see the
numerous other threads about problems while shutting down Indy
servers.

Quote
> 2)   How do I design the client side so that it does not crash when
the
> connection is terminated by the server closing down?

This crash just should not happen.  I have never seen this in Indy 8
or 9.   When the server closes, the client raises an exception, which
I catch & signal to the user that the connection has gone.
Typically, I then loop around with a delay trying to reconnect until
the server comes back.  I have always used TidTCPClient in a read
thread, so, if you are using the main thread with short timeouts,
antifreeze & suchlike bodges, it may have something to do with that.

Rgds,
Martin

Other Threads