Home Help Center

A question about callback

Hi!
I have two programs. One is ICE server,the other is ICE client. After ICE client is runned, the ICE client register a callback object to ICE server program
.I save the callback object in ICE server.

OK,Ice server program can call the object to do something. For example, by the object Ice server program can call a function of Ice client program.
After a while, Ice client program was closed. At that time , ICE server program called the callback object to call a method of Ice client program, a ICE exception was throwed.

My question : How can i Know the client programe was close and not to call the callback object , or how can i catch the exception in my porgram.

Thanks a lot !

Comments

  • skyriverskyriver Member
    my ice file part:
    //////////////////////////////////////////
    class ServerCallBack
    {
    void Connected(int iIP1,int iIP2,int iIP3,int iIP4,string sPCName,string sComputorID);
    void Disconnect(int iIP1,int iIP2,int iIP3,int iIP4,string sPCName,string sComputorID);
    int ReportEvent(AgentEventData poEvent);

    };
    ///////////////////////////////////////////

    server ICE function:
    //////////////////////////////
    RegisterCallbackObj(const ::ServerCallBackPrx& proxy, const ::std::string& sComputorID, const ::Ice::Current& c)
    //////////////////////////////
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    skyriver wrote:
    Hi!
    I have two programs. One is ICE server,the other is ICE client. After ICE client is runned, the ICE client register a callback object to ICE server program
    .I save the callback object in ICE server.

    OK,Ice server program can call the object to do something. For example, by the object Ice server program can call a function of Ice client program.
    After a while, Ice client program was closed. At that time , ICE server program called the callback object to call a method of Ice client program, a ICE exception was throwed.

    My question : How can i Know the client programe was close and not to call the callback object , or how can i catch the exception in my porgram.

    When you invoke an operation on an object whose server has shut down, you will typically get a ConnectionRefusedException or ConnectionLostException. You cannot know in advance whether or not a particular invocation will succed or not, depending on whether the receiving process has exited. Instead, you have to catch the exception and handle it. Something like:
    try {
        someProxy->someOperation(params);
    }
    catch(const Ice::SocketException& ex)
    {
        // invocation failed, deal with that somehow
    }
    

    Of course, you can catch exceptions more specifically, such as catching Ice::ConnectionRefused exception only, and you need not wrap every operation invocation in a try-catch block. Instead, it is often easier to let the exception propagate up the stack and handle it at a higher level of abstraction.

    This is really beyond the scope of Ice and relates more to exception handling in general. In summary, you cannot know whether a particular invocation will succeed or not before actually making the invocation--the only way to find out about the status of the invocation is to see whether it raises an exception.

    Cheers,

    Michi.
Sign In or Register to comment.