Hi Ken-

You've got it: the intent with NSConnection is to vend proxy objects and get proxy objects for the DO system, facilitating communication via obj-c messaging.

I can't speak from much experience on your other options. Apple seems to provide a number of levels of networking abstraction - I can't speak to which would be best for your task... hopefully some others have better expertise!

John

On Dec 3, 2008, at 9:14 PM, Ken Tozier wrote:

Thanks John. That cleared up a few things.

Ultimately, what I want to do, is talk directly to a MySQL database without the need for the MySQL libraries. The libraries target specific processors and OS versions which makes maintenance a royal pain. I was thinking I could bypass the whole library zoo by doing something ike the following

#define DEFAULT_MYSQL_PORT_NUMBER       3306
#define DEFAULT_HOST_NAME       @"locahost"

NSSocketPort *socket = [[NSSocketPort alloc] initRemoteWithTCPPort: DEFAULT_MYSQL_PORT_NUMBER host: DEFAULT_HOST_NAME]; NSConnection *connection = [[NSConnection alloc] initWithReceivePort: nil sendPort: socket];

In tests, this seemed to connect OK, but I take it from your explanation, that I would need to send objective C messages which MySQ doesn't grok. In this case, would I need to set up one or both of NSInputStream, NSOutputStream to send and receive data? Or would I have to go even lower into BSD socked land (a la PictureBrowser) to do this sort of thing?
                

On Dec 3, 2008, at 10:54 PM, John Pannell wrote:

Hi Ken-

I have spent a lot of time in those docs :-) In a nutshell, here's how I see NSConnection and DO... properly set up, NSConnections on the server and client side can enable you to pretty much ignore the fact that two objects live in separate processes. You'll just use regular obj-c messaging between them. On the server side, you get a connection, assign it a root object, and "advertise" its presence:

NSConnection *theConnection = [NSConnection defaultConnection];
[theConnection setRootObject:myServerController];
if(![theConnection registerName:@"myServerName"]){
        // undesirable, but unlikely
}

On the client side, you need to grab the server-side object (the "vended" object in the docs) like so...

id myServerObject = [[NSConnection rootProxyForConnectionWithRegisteredName:@"myServerName host:nil] retain];

You might typically specify a communications protocol to use (an obj-c protocol that you create defining the messages that the server object understands), and also message the server with a reference to self (the client object) so the server can hang on to a reference to it...

[(NSDistantObject *)myServerObject setProtocolForProxy:@protocol(myServerProtocol)];
[myServerObject setClientObject:self];

(Note that "setClientObject" is something you implement yourself, can be named as desired, and its function is to retain a reference to the client object). Now the server can send regular objective-c messages to the client object, and the client can send regular objective-c messages to the server object. Both objects are represented by a stand-in instance of NSDistantObject in each other's address spaces.

Using NSConnection as above, you really don't need any of the other classes you mentioned.

Some caveats: Distributed Objects is not present in the iPhone OS, and I have encountered troubles (that did not have workarounds last I heard) when using DO with garbage collection.

Also to clarify, NSNetService is not directly related to DO, but might be more familiar to you as Bonjour - it is used to discover other processes that advertise their presence on the network.

Hope this helps!

John

Positive Spin Media
http://www.positivespinmedia.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to