Re: Distributed Objects over Network
Re: Distributed Objects over Network
- Subject: Re: Distributed Objects over Network
- From: Chris Kane <email@hidden>
- Date: Mon, 9 Jul 2001 10:14:43 -0700
On Sunday, July 8, 2001, at 05:09 PM, Eric Clements wrote:
I am using Distributed Objects to share objects between 2
applications. They work locally on the same machine when I use "nil"
for the host: parameter, but does not work over the Network between
hosts with "host:" set to @"*" (see below). My goal is to have them
work over the network and I am having NO LUCK. Does anyone know if I
have to do something special to make them work... Here is a snippet of
the code:
Vending App:
-----------------
NSConnection *theConnection = [[NSConnection alloc] init];
[theConnection setRootObject:object];
if ([theConnection registerName:@"MonitorSrcDict"
withNameServer:[NSPortNameServer
systemDefaultPortNameServer]] == NO) {
NSLog( @"Couldn't Register %@", name );
}
Client App:
-----------------
srcDictConnection = [NSConnection
connectionWithRegisteredName:@"MonitorSrcDict"
host:@"*" usingNameServer:[NSPortNameServer
systemDefaultPortNameServer]];
Others have given some more complete answers, but another reason this
doesn't work is the port name server you're using. The default port
name server only does naming service (1) for a type of NSPort transport
(NSMachPort) which works within the machine only and (2) does it in such
a way that it named lookup can only be done within a machine. (A subtle
distinction not worth worrying about).
You need to use NSSocketPorts as the NSConnection ports, and create the
connection with -initWithReceivePort:sendPort: (or whatever the name of
the method is). I will forward a followup mail message to this list
with an example I created several months ago.
Chris Kane
Cocoa Frameworks, Apple