Distributed Object (newbie problem)

Joined
Apr 24, 2010
Messages
5
Reaction score
0
Points
1
Location
Ireland
Your Mac's Specs
Dual 1GHz G4 OSX10.4.11
Hello

I am relatively new to Cocoa but learning fast.
I have a specific problem which I hope may be answered by the
expertise on this forum.

I cannot seem to get a 'client' app to make a connection to a vended
object in a 'server' app. The relevant code in my 'server' app is:

- (void)awakeFromNib {

// create the comms port for receiving
port = [[[NSSocketPort alloc] initWithTCPPort:60000] retain];
NSLog(@"Socket Port = %@", [port address]);

// set up, retain and register connection
connection = [[[NSConnection alloc] initWithReceivePort: port sendPort: nil] retain];
[connection registerName: @"medix"];

[connection setRootObject:self];

NSLog(@"Connection = %@", connection);

}


This seems to work fine. The port is open and the NSLog confirms the
structure of the connection.

The problem lies in my 'client' code (I think):

- (void)awakeFromNib {

// set up and retain connection
connection = [[NSConnection connectionWithRegisteredName:mad:"medix" host:mad:"192.168.1.2"] retain];

NSLog(@"Connection Setup %@\n\n\n", connection);

remObject = [connection rootProxy];

NSLog(@"Connection Setup %@\n\n\n", remObject);

[remObject retain];

}


.. which refuses to connect and which does NOT display the remObject
structure in NSLog, but simply (null).

Am I doing something so obviously crazy that I can't see it ? ? :(

Thanks in advance

Chris
 
OP
C
Joined
Apr 24, 2010
Messages
5
Reaction score
0
Points
1
Location
Ireland
Your Mac's Specs
Dual 1GHz G4 OSX10.4.11
Problem solved by me after much trial and error work !
-
In the 'server', use:

- (void)awakeFromNib {

port = [[NSSocketPort alloc] initWithTCPPort:60000];

connection = [[[NSConnection alloc] initWithReceivePort:port sendPort:port] retain];

[connection setRootObject:self];

return;

}


In the 'client', use:

- (void)awakeFromNib {

port = [[NSSocketPort alloc] initRemoteWithTCPPort:60000 host:mad:"192.168.1.2"];

connection = [[[NSConnection alloc] initWithReceivePort:nil sendPort:port] retain];

remObject = [[connection rootProxy] retain];

return;
}


This does not require registration with a port name server or any
other code overhead, and seems to work flawlessly.

Just in case anyone else is struggling with this.
Woefully poor explanations in most textbooks and in the Apple
documentation, as per usual :Grimmace:

Chris
 
OP
C
Joined
Apr 24, 2010
Messages
5
Reaction score
0
Points
1
Location
Ireland
Your Mac's Specs
Dual 1GHz G4 OSX10.4.11
PS:

Of course, as this is in an -awakeFromNib method I have to release the
connection objects and the proxy if the window gets closed and reopened
in the app otherwise it will leak like fun. :Oops:

Chris
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top