WiFi Aware connection cannot be established when both peers publish and subscribe

It works when one device is only a publisher and the other is only a subscriber. However, when both devices act as both publisher and subscriber simultaneously—which Apple’s documentation (https://developer.apple.com/documentation/wifiaware/adopting-wi-fi-aware#Declare-services) indicates is valid—the connection never establishes. After timing out, both NetworkListener and NetworkBrowser transition to the failed state. This appears to be a race condition in Network framework.

Task.detached {
    try await NetworkListener(
        for: .wifiAware(
            .connecting(
                to: .myService,
                from: .allPairedDevices,
                datapath: .defaults
            )
        ),
        using: .parameters {
            Coder(
                sending: ...,
                receiving: ...,
                using: NetworkJSONCoder()
            ) {
                TCP()
            }
        }
    ).run { connection in
        await self.add(connection: connection)
    }
}

Task.detached {
    try await NetworkBrowser(
        for: .wifiAware(
            .connecting(
                to: .allPairedDevices,
                from: .myService
            )
        ),
        using: .tcp
    ).run { endpoints in
        for endpoint in endpoints {
            await self.connect(to: endpoint)
        }
    }
}

FB21527009

WiFi Aware connection cannot be established when both peers publish and subscribe
 
 
Q