• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc


  • Subject: Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
  • From: John Pannell <email@hidden>
  • Date: Wed, 3 Dec 2008 20:54:51 -0700

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

On Dec 3, 2008, at 8:22 PM, Ken Tozier wrote:

Hi

I'm working my way through the "Distributed Objects" documentation and am confused about when to use NSConnection, NSInputStream, NSOutputStream etc. The PictureBrowser example project doesn't even seem to use NSConnection and does its thing just fine. Reading the NSConnection docs, I notice the conspicuous absence of any method that actually allows the transfer of messages and data. It just seems like something that allows you to connect to something ... and then has not a single method to actually do anything with that connection.

I looked at several of the example projects but they're all over the map. Some use CF functions, some use raw BSD sockets, PictureBrowser uses NSNetService (something not even mentioned in the Distributed Object docs) So what is the overview of the function and interrelationships between these different parts and importantly, what exactly does one do with an NSConnection?


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
      • From: Ken Tozier <email@hidden>
References: 
 >Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: Programmatically loading an NSImage via other field
  • Next by Date: Re: How to make a RunLoop patiently do nothing?
  • Previous by thread: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
  • Next by thread: Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
  • Index(es):
    • Date
    • Thread