Re: NSInputStream vs GCD's Dispatch Sources
Re: NSInputStream vs GCD's Dispatch Sources
- Subject: Re: NSInputStream vs GCD's Dispatch Sources
- From: Jens Alfke <email@hidden>
- Date: Sun, 13 Oct 2013 17:46:21 -0700
On Oct 13, 2013, at 3:18 PM, Todd Heberlein <email@hidden> wrote:
> On one hand there is the NSStream option (e.g., NSInputStream). It looks a moderately awkward setting up an initial connection (not as nice as NSURLConnection), and then it seems I schedule it on a run loop (probably the main run loop?).
You’re right, it is awkward to set up. In particular, to avoid using the deprecated NSHost class, you should create the streams by calling CFStreamCreatePairWithSocketToHost — this creates CFStreams, which are toll-free bridged to NSStreams.
You can schedule it on any runloop you want. Using the main runloop is convenient, and probably OK if your callbacks don’t take very long to run. Otherwise you can create a new NSThread and start it up on that.
> On the other hand is the GCD Dispatch Sources.
Here I agree with Marcelo that GCDAsyncSocket is the way to go. The only downside is that there’s more API to learn, and you’re adding a dependency on a 3rd party (open source) library. But it’s a lot more modern and capable than the creaky NSStream stuff.
—Jens
_______________________________________________
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