Network Framework: Choosing Interface Types for Browsing/ Advertising

I am using Network framework for connecting two iPad devices that are connected through LAN and has Wifi enabled. I have enabled peerToPeerIncluded. I would like to understand how the framework chooses the interface types for browsing and discovering devices. When I start a browser with browser.run or listener.run, does the browser and advertiser browse and listen on all available interface types? My concern is that if it does in only one interface, Is there a chance that the browser is browsing in one interface(Lets say WiredEthernet) and the listener is listening on another interface(Lets say AWDL) and they dont discover?

Answered by DTS Engineer in 878471022
does the browser and advertiser browse and listen on all available interface types?

Yes.

At least by default. If you don’t want that behaviour, you can limit it to a specific interface type or a specific interface. The exact mechanism you use depends on which Network framework API you’re using. You mentioned the run(_:) method which suggests you’re using the shiny new one. In that case, the droids you’re looking for are listed here (search that page for interface).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer
does the browser and advertiser browse and listen on all available interface types?

Yes.

At least by default. If you don’t want that behaviour, you can limit it to a specific interface type or a specific interface. The exact mechanism you use depends on which Network framework API you’re using. You mentioned the run(_:) method which suggests you’re using the shiny new one. In that case, the droids you’re looking for are listed here (search that page for interface).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

If you don’t want that behaviour, you can limit it to a specific interface type or a specific interface

For most cases I am ok to let the Network framework decide the interface type. But there are some cases where I want to allow only peer to peer. I've been using prohibitedInterfaceTypes to restrict wiredEthernet but I've not been able to restrict it to use only peer to peer. If I put .wifi in the prohibitedInterfaceTypes it doesnt connect through peer to peer either. Is there a way to force peer to peer only?

The original question was related to browsing alone. But I would want to do the interface type restriction for the connection as well.

@DTS Engineer I ran some more tests on this today. Here are the results:

Device setup: Both the devices are connected to same infrastructure wifi and not connected to Ethernet.

Case 1:

Browser setup:

parameters.prohibitedInterfaceTypes = [.wifi]
parameters.includePeerToPeer = true

Connection setup:

.prohibitedInterfaceTypes([.wifi])
.peerToPeerIncluded(true)

In above case The devices are getting discovered. But unable to connect. I see below error when trying to send a message after initiating a connection(The connection never moves to ready state): (Network.NWError error 89 - Operation canceled)

Case 2:

Browser setup:

parameters.prohibitedInterfaceTypes = [.wifi]
parameters.includePeerToPeer = true

Connection setup:

.prohibitedInterfaceTypes([])
.peerToPeerIncluded(true)

In above case, devices are getting discovered as well as getting connected.

Your setup, prohibiting Wi-Fi and enabling peer-to-peer, is contradictory — peer-to-peer Wi-Fi is a ‘subclass’ of Wi-Fi — so I’m not surprised you’re seeing weird results.

But there are some cases where I want to allow only peer to peer.

I don’t think that’s feasible without how the networking stack currently works.

Well, assuming you’re talking about Apple peer-to-peer Wi-Fi, which is what includePeerToPeer controls. You could change tack and set up your connection with Wi-Fi Aware. IIUC such a connection will never run over infrastructure Wi-Fi.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Network Framework: Choosing Interface Types for Browsing/ Advertising
 
 
Q