New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Distributed Object (newbie problem)


Post Reply New Thread Subscribe

 
Thread Tools
chriseccles

 
Member Since: Apr 24, 2010
Location: Ireland
Posts: 5
chriseccles is on a distinguished road
Mac Specs: Dual 1GHz G4 OSX10.4.11

chriseccles is offline
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:@"medix" host:@"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
QUOTE Thanks
chriseccles

 
Member Since: Apr 24, 2010
Location: Ireland
Posts: 5
chriseccles is on a distinguished road
Mac Specs: Dual 1GHz G4 OSX10.4.11

chriseccles is offline
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:@"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

Chris
QUOTE Thanks
chriseccles

 
Member Since: Apr 24, 2010
Location: Ireland
Posts: 5
chriseccles is on a distinguished road
Mac Specs: Dual 1GHz G4 OSX10.4.11

chriseccles is offline
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.

Chris
QUOTE Thanks

Post Reply New Thread Subscribe


« need help missing header files with gcc | NSString containing IvP4 of machine »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
newbie to forum, have a problem with my Mini? Chertin Apple Desktops 3 04-04-2010 04:52 PM
Required properties for burn object to burn a cd in mac system m_shivakumar OS X - Operating System 0 12-08-2009 05:39 AM
Imac early 2006 core duo graphics card problem; mircomandrillo Apple Desktops 0 12-03-2009 04:03 AM
Huge Graphics Problem With Magic Garage Band mattcooper87 OS X - Apps and Games 0 08-21-2007 08:23 AM
newbie problem.. Jon Switcher Hangout 22 08-11-2003 07:45 PM

All times are GMT -4. The time now is 05:16 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?