• 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: Ken Tozier <email@hidden>
  • Date: Wed, 3 Dec 2008 23:14:55 -0500

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

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: "Michael Ash" <email@hidden>
    • Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
      • From: John Pannell <email@hidden>
References: 
 >Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc (From: Ken Tozier <email@hidden>)
 >Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc (From: John Pannell <email@hidden>)

  • Prev by Date: Re: How to make a RunLoop patiently do nothing?
  • Next by Date: Re: How to display simple dialog at application startup?
  • Previous by thread: Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
  • Next by thread: Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
  • Index(es):
    • Date
    • Thread