Troubleshooting Peer-to-Peer Connection Failure between iOS Apps Using NWListener, NWConnection, and STUN

I am currently developing two iOS applications that require peer-to-peer connectivity. To facilitate this, I've implemented NWListener and NWConnection in both apps for network communication. To determine each device's public IP address and port—necessary for establishing a connection over the internet through my mobile operator's Carrier-Grade NAT (CGNAT)—I'm using a STUN server.

Despite successfully retrieving the external IP addresses and ports for both devices, I am unable to establish a peer-to-peer connection between them. My current setup involves initiating a connection using the public addresses and ports discovered through the STUN server response. However, all attempts to connect the devices directly have been unsuccessful.

I am seeking guidance on whether there are additional considerations or specific configurations needed when using NWListener, NWConnection, and a STUN server to establish a direct connection between devices in a CGNAT environment. Is there a particular step or network configuration I might be missing to successfully connect both iOS devices to each other using their external network details?

You tagged your thread with QUIC, but I don’t see any mention of it in your post. Are you trying to run this connection using QUIC?

If so, I recommend that, just for testing purposes, you start with TCP and then move on to UDP and then move on to QUIC.

Share and Enjoy

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

Troubleshooting Peer-to-Peer Connection Failure between iOS Apps Using NWListener, NWConnection, and STUN
 
 
Q