Archived
This forum has been archived. Please start a new discussion on GitHub.
How to catch ConnectionLostConnection exception in cpp?
Vitaly Berov
in Help Center
Hello,
I've just started evaluation of Ice (cpp).
Ice runtime throws ConnectionLostConnection exception somewhere in its threads when connection is lost. What is supposed way to catch this exception?
Vitaly Berov
I've just started evaluation of Ice (cpp).
Ice runtime throws ConnectionLostConnection exception somewhere in its threads when connection is lost. What is supposed way to catch this exception?
Vitaly Berov
0
Comments
-
Hi,
An Ice::ConnectionLostException exception indicates that the peer closed the connection.
On the server side, it's raised by the Ice runtime and catched by the server thread pool which takes care of cleaning up the connection resources. There's nothing to worry about, you'll never have to catch it.
On the client side, if the connection is closed by the peer while you're making an invocation, an Ice::ConnectionLostException might be raised and should be catch by your code like any other Ice::LocalException that an Ice invocation might raise.
Cheers,
Benoit.0 -
help: how to catch ConnectionLostException at client?
I've been wondering how to catch ConnectionLostException at client application.
Here's a summary of what I'm doing:
My server/client use bidirectional communication in a way that the sample codes ( Ice.bidir.client/server) do.
If I terminates a server after a client connects to a server, the following warning is printed out (Ice.Warn.Connections = 1) :
connection exception:
TcpTransceiver.cpp:191: Ice::ConnectionLostException:
connection lost: WSAECONNRESET
The message above prints out as soon as a server terminates, i.e., a client is disconnected, but the thing is that I cannot catch that exception.
Could you guide me how to catch it or more specifically, in which thread should I catch it? I want to use that exception in order to do some state initialization in my app.
If you could explain it using Ice.bidir.server/client sample codes, it would be great.
Thank you in advance.
0 -
Hi,
There are no ways to catch this exception. It's in general not a good idea to rely on the Ice runtime to detect that the connection was lost since this isn't reliable (while it appears to work in your case, it might not if the client crashes and/or is behind multiple network routers). See also this FAQ on this subject. To setup/destroy state, I recommend using the session pattern instead, see demo/Ice/session for example and the links provided in the FAQ.
Cheers,
Benoit.0
