Re: Directly creating NSNetService
Re: Directly creating NSNetService
- Subject: Re: Directly creating NSNetService
- From: Rick Mann <email@hidden>
- Date: Sun, 09 Sep 2012 23:06:54 -0700
Awesome, thanks for the explanation. I'm still puzzled by the docs, though. They clearly say I can use it directly.
But this'll work.
--
Rick
On Sep 9, 2012, at 23:02 , Jens Alfke <email@hidden> wrote:
>
> On Sep 9, 2012, at 8:42 PM, Rick Mann <email@hidden> wrote:
>
>> I want to connect to a TCP or UDP server socket without going through bonjour browsing in iOS, for a voip app. The docs say, "If your application is the client of a network service, you can either create anNSNetService object directly (if you know the exact host and port information)…"
>
> If you already know the address, you don’t need an NSNetService at all. Mac OS has the NSStream method
>
> + (void)getStreamsToHost:(NSHost *)host port:(NSInteger)port inputStream:(NSInputStream **)inputStream outputStream:(NSOutputStream **)outputStream;
>
> but we’re advised not to use it because NSHost is deprecated (it makes synchronous DNS lookups that can block for a long time if the network is flaky), and this method doesn’t exist at all on iOS. So instead, call
>
> void CFStreamCreatePairWithSocketToHost(CFAllocatorRef alloc, CFStringRef host, UInt32 port, CFReadStreamRef *readStream, CFWriteStreamRef *writeStream);
>
> Since CFStream and NSStream are toll-free bridged, you can just cast the parameters to an NSInputStream** and NSOutputStream**. Don’t forget to release them when you’re done, since this is a CF call and it’ll hand you objects with a +1 refcount.
>
> —Jens
--
Rick
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden