Archived

This forum has been archived. Please start a new discussion on GitHub.

Question about ConnectionLost

hi,
In bidir circumstance, I create a thread in client to reigster the callbacks periodically to the server in case that the server suddenly breaks down but restart again. The client , actually a service, is not necessary to restart and can keep working with the server.
Are there any better solutions so that I just need retry to register the callbacks only when I detect the connection lost or connection closure. Try-catch?

Best Regareds
OrNot

Comments

  • matthew
    matthew NL, Canada
    You could have the server ping the client at regular intervals. If no ping arrives, then the client must re-register.
  • hi,Matthew,
    Do you actually mean let client ping server in my scenario?
    So far the ping solution , I think it is a "positive method to detect the server status as what I now adopt to register callbacks periodically . I am afraid these frequent pings will result in some overloads to server.
    Can I have some "defensive" methods to register the callback such as :

    try
    {
    .......
    }
    catch(Ice::ConnectionLostException)
    {
    registerCallbacks();
    }


    But I am doubting about this strategy because it seems difficult to arrange the try-catch especially with the thread-pool model.


    Hope getting your further ideas.
    Thanks

    OrNot
  • matthew
    matthew NL, Canada
    Without knowing your architecture in more detail ts very hard to give very good advice. Why do you think that using a thread pool is makes it more difficult to reestablish the connection?
  • hi, Mathrew,
    I am looking for a method to know the server's status ,especially the server's closure.

    1) If the client has GUI, I hope the client can know the server's down even the client are not sending requests at the moments. For example, the client can pup up a massgebox to give the server down message.
    2) if the client is a service, I also hope the client can know the server's down and start a thread to try to reestiblish the connection until server is re-up.

    I notice that Ice can trace this , but I have no ideas how to catch this in my client program especially in thread pool mode.

    Thank you very much.

    OrNOt
  • As Matthew wrote, you must write a monitor thread (or something similar) that regularly pings the server to find out if it is still alive.

    There is no other way to reliably detect if a server is still alive. In some cases, the TCP/IP stack can detect if a server goes down (that's when you see the trace message), but in many other cases, it can't. For example, if you run the client and server over DSL and cut the phone line, then you won't get this log message until the client actively tries to send something to the server.
  • hi,Marc,
    Thanks for your clear answer.
    But, if anyway, I want to know if the server is still alive as ice trace does even it is not very realiable , do I have opporunity to catch that signal from my program as ice trace does with the current version 2.1.2?

    Cheers
    OrNot
  • No, you cannot. You can only catch the exception if you invoke an operation.