Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
- Subject: Re: Big picture relationships between NSConnection, NSInputStream, NSOutputStream etc
- From: "Michael Ash" <email@hidden>
- Date: Thu, 4 Dec 2008 00:23:19 -0500
On Wed, Dec 3, 2008 at 11:14 PM, Ken Tozier <email@hidden> 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?
NSConnection is for distributed objects and nothing else. Despite the
name it is *not* a general-purpose IPC mechanism. As such, it only
works for talking to other Cocoa programs (and only if they're
prepared to accept distributed objects connections), so using it for
MySQL is Right Out.
If you create a pair of NSStreams with a socket then it provides you
with essentially a direct wrapper for the BSD socket stuff. (It is so
direct that the -read: and -write: methods have the exact same
semantics as the read() and write() functions despite not being
documented this way for at least one or two OS revisions.) I've found
NSStream to be the most convenient way for dealing with sockets in a
Cocoa app in most situations, but you can certainly feel free to hit
the BSD layer or use one of the other free sockets wrappers if you
prefer.
Mike
_______________________________________________
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