Home Help Center

How to find out if the connection is lost?

renzorenzo Member Aleksey BlokhinOrganization: JSC "SRI Vector"Project: Remote host monitoring system
Hi!

So, suppose a client application pings a server every 5 seconds to see whether it is running. After starting the server, the client application establishes a tcp-connection. But how do you know that the connection has been disconnected? Now the application continues to ping the server every 5 seconds, but can I get rid of it? Is there any way to find out about the state of a connection? Without a ping to the server.

Thank you!

Comments

  • renzorenzo Member Aleksey BlokhinOrganization: JSC "SRI Vector"Project: Remote host monitoring system
    I mean if I start a simple server and client and then close the server, I see the following message on the client-side:
    ==> -- Network: received 14 of 14 bytes via tcp
        -- Protocol: received close connection
        -- Network: closing tcp connection
    

    And if I forcibly close my server, I get the following message on the client-side:
    ==> -- warning: connection exception:
           TcpTransceiver.cpp:469: Ice::ConnectionLostException
        -- Network: closing tcp connection
    

    Thus a TraceUtil knows about shutting down the server, but how can I know this? How can I know that the connection is closed without any requests to the server?
  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi,

    ping the server at regular intervals is the recommended approach, see Why does Ice not provide a callback to notify of connection closure?
  • renzorenzo Member Aleksey BlokhinOrganization: JSC "SRI Vector"Project: Remote host monitoring system
    "The TCP/IP stack doesn't provide reliable connection closure notifications"
    But what about keepalive packets or rst signals?
    "For example, a TCP/IP connection can be left in a half-open state where the peers won't detect the connection loss until they actually try to send data over the connection."
    But your trace util notifies of connection closure, as in the case of properly closing the connection (it prints "received close connection") and in the case of unexpected closure ("Ice::ConnectionLostException").

    And as far as I understand, this is done without a ping to the server.
    I mean Ice should provide not a callback but some function like isConnectionLost() returns true if connection was closed and it's the well-known via tcp without ping the server.
  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Some times "Ice::ConnectionLostException" is only throw after you try to send data over the connection, the only reliable way to keep a connection open is to send packets this will allow you application to detect the connection lost in a timely manner.

    Why do you need this, what is your application trying to do?
  • renzorenzo Member Aleksey BlokhinOrganization: JSC "SRI Vector"Project: Remote host monitoring system
    Just have the task to minimize the traffic between the nodes the network. It was minimized as far as possible by high-level tools, and now I think how can I get rid of ping servers every N seconds.

    Many thanks for your answers!
Sign In or Register to comment.