Using NWConnection, can you choose a specific interface name to use?

When initializing a NWConnection I noticed in NWParameters you can require or prohibit types of interfaces such as wifi, cellular, or wiredEthernet. I want to explicitly use awdl0 and not en0. Both are wifi type interfaces. I noticed sometimes my device uses en0 and other times uses awdl0.

Using NWConnection, can you choose a specific interface name to use?

No. This is a very deliberate design choice, with the goal being to get folks away from hard wiring interface names and instead focusing on attributes of those interfaces.

I noticed sometimes my device uses en0 and other times uses awdl0.

OK. And that’s a problem because?

Share and Enjoy

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

Hi there, I do have the same questions regarding choosing awdl0 vs en0.

OK. And that’s a problem because?

At least for my case where I'm designing a peer to peer file transfer app, awdl0 performs way better compared to en0. (tested in multiple environments). I really would like to have a way to at least set as awdl0 as preferred.

I found that on newConnectionHandler callback of NWListerner, we get the interface name using "connection.endpoint.interface.name" and we can create a logic behind to allow connection if awdl0 is present on interface name first and then if no attempts come with awdl0 we can accept the connection using en0. (I know it is not a good practice writing interface names, but it is at least a work around to prioritize given reasons just mentioned).

I have some follow questions here. Let's assume BOTH devices are connected to the same wi-fi infrastructure.

  • Say I have a device A. When setting up a bonjour service (NWListener.Service) and set parameters as includePeerToPeer on tcpOptions, would it always create a awdl0 endpoint? Peer my tests is always create a en0 endpoint and awdl0 endpoint.
  • Say I have a device B that will connect to the bonjour service from device A (as mentioned above). When device B calls "NWConnection(to: endpoint, using: parameters) will it always attempt to connect ALL interfaces available (including awdl0)? (Assuming parameters here also incudes "includePeerToPeer"). I wonder because sometimes I add a debug on "newConnectionHandler" from device A (listener) and sometimes it receives en0 first, sometimes awdl0 first and I saw cases where I didn't receive awdl0.
  • Is the answer the same when both are connected to Wi-Fi infrastructure but from different networks?
  • Is the answer the same when both are NOT connected to Wi-Fi infrastructure?

I know from testings that whenever one of the devices are no connected to infrastructure Wi-Fi we always connect using awdl0 ('cause there's no way to connect without using awdl0), but really want to understand how "NWConnection(to: endpoint, using: parameters)" works behind the scenes.

Last questions is: is awdl0 interface available on all iphones using iOS 12.0 or above? (wondering because includePeerToPeer is iOS12+).

Thanks.

Using NWConnection, can you choose a specific interface name to use?
 
 
Q