Detecting/Repairing NSConnection failure

Posted by anthony on Stack Overflow See other posts from Stack Overflow or by anthony
Published on 2010-04-15T21:19:59Z Indexed on 2010/04/15 21:23 UTC
Read the original article Hit count: 314

I would like to use NSConnection/NSDistributedObject for interprocess communication. I would like the client to be able to handle the case where the server is only occasionally reachable.

How can I determine if sending a message to the NSConnection will fail or has failed? Currently if my server (the process that has vended the remote object) dies, the client will crash if it sends a selector to the remote object.

Ideally I'd like to have a wrapper for the remote object that can lazily instantiate (or reinstantiate) the connection, and return a default value in the case where the connection could not be instantiated, or the connection has failed. I don't really know the correct way to do this using objective c.

Here's some pseudocode representing this logic:

if myConnection is null:
    instantiate myConnection
    if MyConnection is null:
        return defaultValue

    try
        return [myConnection someMethod]
    catch
        myConnection = null
        return defaultValue

© Stack Overflow or respective owner

Related posts about nsconnection

Related posts about nsdistantobject