Is it possible to connect different hosts on LAN with NSXPCConnection?


Akifumi Takata
 

Dear all,

I am developing a persistent object framework (object oriented database) called the Nursery framework. https://github.com/Nursery-Framework/Nursery

In that framework I am using a deprecated NSConnection to connect the server and client so I'm trying to replace it with NSXPCConnection.

I could confirm that I can create applications and daemons for testing and connect on the same host.
However, running the application on another host failed to connect to the daemon.

Can NSXPCConnection not connect between different hosts?

Regards,
Akifumi Takata

Code excerpt:

@protocol xpctestprotocol <NSObject>

- (void) put: (NSString *) aString replay: (void (^) (NSString * aString)) aReply;

@ end

@implementation AppDelegate

- (void) applicationDidFinishLaunching: (NSNotification *) aNotification {
    // Insert code here to initialize your application
    NSXPCConnection * aConnection = [[NSXPCConnection alloc] initWithMachServiceName: @ "org.nursery-framework.xpctest" options: NSXPCConnectionPrivileged];
    NSXPCInterface * anInterface = [NSXPCInterface interfaceWithProtocol: @protocol (xpctestprotocol)];
    [aConnection setRemoteObjectInterface: anInterface];
    [aConnection resume];
    id <xpctestprotocol> aDaemon = [aConnection remoteObjectProxy];
    [aDaemon put: @ "Hello" replay: ^ (NSString * aString) {
        NSLog (@ "% @", aString);
        [self performSelectorOnMainThread: @selector (updateUI :) withObject: aString waitUntilDone: NO];
    }];
}

- (void) updateUI: (NSString *) aString
{
    [[self textField] setStringValue: aString];
}

@ end

@implementation xpctestdaemon

- (BOOL) listener: (NSXPCListener *) listener shouldAcceptNewConnection: (NSXPCConnection *) newConnection
{
    NSXPCInterface * anInterface = [NSXPCInterface interfaceWithProtocol: @protocol (xpctestprotocol)];
    [newConnection setExportedInterface: anInterface];
    [newConnection setExportedObject: self];
    [newConnection resume];
    return YES;
}

- (void) put: (NSString *) aString replay: (void (^) (NSString *)) aReply
{
    aReply ([aString stringByAppendingString: aString]);
}

@ end

org.nursery-framework.xpctest.plist is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.nursery-framework.xpctest</string>
<key>Program</key>
<string>/Users/aki/Library/Developer/Xcode/DerivedData/xpctest-cpkkdfbfxfkomkfzkazhhmjxtoea/Build/Products/Debug/xpctest</string>
<key>MachServices</key>
<dict>
<key>org.nursery-framework.xpctest</key>
<true/>
</dict>
</dict>
</plist>

Join {cocoa@apple-dev.groups.io to automatically receive all group messages.