Network Framework: reconnection during interface change

I'm trying to establish a tcp connection to server using Network Framework (nw_connection_t in obj-c). As a draft I use tcp echo server tcpbin.com with default connection parameters. Everything works fine: connection establishing, sending and receiving data.

But when I disable wifi network via Control Center, established connection doesn't drop, connection status doesn't change in nw_connection_set_state_changed_handler until remote side drops connection by timeout. Meantime nw_connection_set_path_changed_handler reports that wifi network path is "unsatisfied" and cellular connection is available. The same thing happens when I switch from cellular to wifi network via Control Center.

Questions are:

  1. Should nw_connection_t change its state to nw_connection_state_failed and\or nw_connection_state_waiting when the current network path becomes unavailable?
  2. What is the recommended way to switch from the inactive interface (or interface without internet) to working one?

iOS version is 17.3.

1. Should nw_connection_t change its state

Well, answers to “should” questions depend on your perspective (-: However, the behaviour you’ve described in the expected behaviour. As a matter of policy, Network framework does not tear down connections that become unviable. That’s because the connection could become viable again in the future. If you want to proactively tear them down, you have a number of callbacks to trigger that, including the path changed handler, the viability changed handler, and the better path available handler.

2. What is the recommended way to switch from the inactive interface (or interface without internet) to working one?

A TCP connection is identified by the tuple source address / source port / destination address / destination port. If the source interface goes down, the connection becomes unviable; there’s no way to bring it back to life without bringing that interface up [1]. So, if you’re limited to TCP [2] then you have to open a new connection.

Share and Enjoy

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

[1] And ever that only works if it gets the same IP address.

[2] There are alternatives here, most notable MPTCP.

Network Framework: reconnection during interface change
 
 
Q