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.

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?

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" "">
<plist version="1.0">

Join { to automatically receive all group messages.