简体   繁体   中英

Creating NSDistantObject

I have two applications 'A' and 'B' and need to do some ipc. Process 'A' launches process 'B' if it is not already running. In process 'A' I create NSConnection and registerName: . In process 'B' , I get the remote object by calling rootProxyForConnectionWithRegisteredName: . And it sets client object pointer to remote object so that Process 'A' uses that object to call client object methods. Until process 'B' launches and establishes connection the _clientObj is nil. I might receive events that are intended to _clientObj .


@interface Server : NSObject {
    @private
    id _clientObj;
}

Question: Is there a way so that i make _clientObj as NSDistantObject and it holds all the messages until _clientObj is constructed.

The functionality you request is not available straight out of the box, but you could create a subclass of NSDistantObject that captures incoming method calls and puts them in a queue until the connection becomes valid. Once the connection becomes valid, it could then dequeue and forward all of the stored method calls. Any further method calls would then be forwarded "live", so to speak.

Have a look at this code as a possible example of how to create a subclass of NSDistantObject to do what I've described above.

GTMTransientRootProxy.m , GTMTransientRootProxy.h

This code silently swallows method calls on the NSDistantObject while the connection is down, but you could extend it to queue the method calls during downtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM