Subject: NSNetService Connection Priorities
From: David Carroll
Date: 15 Sep 2017
I am using the NSNetService and NSNetServiceBrowser to establish a
connection between two iPads. However, I need the ability to better
control a connection and priority of the various connections between the
two iPads. Specifically, I like a way to set the following connection
priority.
1) Ad-hoc Wifi
- This only works if the device is disconnected from the network
- This does not seem to work on iPad-2 (9.3.5)
2) Ad-hoc Bluetooth
- This does not work on iOS11
3) Wifi - network connected
- This appears to be Bonjour's current default network priority
Unfortunately, I have looked through the API's and do not see a good way
using Bonjour and the NSNetService an NSNetServiceBrowser APIs.
I don't want to have to rewrite and retest the entire connection
mechanism and verify that is works between all the various types of
iPads. So I am looking for a way within NSNetServer and
NSNetServiceBrowser APIs to better control the connection.
So I am looking for a way to perform any of the following:
1) Prioritize connections using Bonjour
2) Detect the various connection types with Bonjour
3) Disable or ignore various connection within Bonjour
I'm looking at a way to perform this within
NSNetServiceBrowser:didFindService.
Any thoughts or suggestions?
David
* * *
From: Quinn "The Eskimo!"
Date: 15 Sep 2017
On 15 Sep 2017, at 12:39, David Carroll wrote:
> So I am looking for a way within NSNetServer and NSNetServiceBrowser
> APIs to better control the connection.
That's not possible with the NSNetService API. The only control you
have there is whether to include peer-to-peer interfaces at all (via the
`includesPeerToPeer` property). You can't control the resolution
priority.
You might be able to make some progress using the lower-level DNS-SD
API, <dns_sd.h>. This has separate knobs for the two different
peer-to-peer types.
If you do decide to investigate the DNS-SD API, check out the
DNSSDObjects sample code, which is an Objective-C wrapper around DNS-SD
that makes it easier for folks coming from NSNetService.
<https://developer.apple.com/library/content/samplecode/DNSSDObjects/>
> This does not seem to work on iPad-2 (9.3.5)
That's expected. Peer-to-peer Wi-Fi requires a device with a Lightning
connector (the Lightning connected isn't actually relevant here, it's
just a happy coincidence that these two are correlated).
Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
* * *
From: Jens Alfke
Date: 15 Sep 2017
On Sep 15, 2017, at 4:39 AM, David Carroll wrote:
> So I am looking for a way to perform any of the following:
> 1) Prioritize connections using Bonjour
> 2) Detect the various connection types with Bonjour
> 3) Disable or ignore various connection within Bonjour
In general, Bonjour is only responsible for discovering the service, not
for connecting to it. NSNetService does have a method to open a
connection, but (as I understand it) it's mostly a convenience that
first resolves the IP address and then calls NSStream to open a socket
to that address+port.
However, I'm not sure how this ties in with the OS's ability to connect
over Bluetooth or ad-hoc WiFi. I don't know if these connection modes
manifest as different IP addresses, or different network interfaces.
In other words, when a peer is reachable through two or more of the
modes you list, I don't know if resolving the NSNetService will show a
different IP address corresponding to each mode, and if so, whether it's
possible to choose one of those addresses and then connect to it and get
that mode. If so, it seems this would solve your problem. Quinn?
--Jens
* * *
From: Quinn "The Eskimo!"
Date: 15 Sep 2017
On 15 Sep 2017, at 17:04, Jens Alfke wrote:
> However, I'm not sure how this ties in with the OS's ability to
> connect over Bluetooth or ad-hoc WiFi.
Needless to say this is complex, but the short summary is that when you
resolve a Bonjour service discovered over peer-to-peer the system brings
up a peer-to-peer interface (if it's not up already) and from there
every runs like normal TCP/IP.
> In other words, when a peer is reachable through two or more of the
> modes you list, I don't know if resolving the NSNetService will show a
> different IP address corresponding to each mode ...
It won't, at least in the most common case of being able to see the
service over both peer-to-peer and infrastructure. Bringing up a
peer-to-peer interface is expensive, so the system won't do it unless it
has to.
Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
* * *
From: Quinn "The Eskimo!"
Date: 15 Sep 2017
[I didn't want to respond to the following until I receive positive
confirmation from the Bonjour team.]
On 15 Sep 2017, at 12:39, David Carroll wrote:
> 2) Ad-hoc Bluetooth
> - This does not work on iOS11
Peer-to-peer Bluetooth is not supported on iOS 11 and friends.
Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
* * *
From: Jens Alfke
Date: 15 Sep 2017
On Sep 15, 2017, at 9:30 AM, Quinn "The Eskimo!" wrote:
> Peer-to-peer Bluetooth is not supported on iOS 11 and friends.
Can you share any information on the reason for this regression? Like,
was it deemed unnecessary because ad-hoc WiFi works just as well, or was
it unreliable, or ... ?
(Also, does this apply to macOS 10.13? IIRC, TCP-over-BT work(ed) on
Macs too?)
--Jens
* * *
From: Quinn "The Eskimo!"
Date: 18 Sep 2017
On 15 Sep 2017, at 18:35, Jens Alfke wrote:
> Like, was it deemed unnecessary because ad-hoc WiFi works just as well
> ...
I'm not familiar with all the decision making but my understanding is
that the above was a big part of it.
> IIRC, TCP-over-BT work(ed) on Macs too?
Bluetooth peer-to-peer networking was never supported on macOS.
Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware