Peer-to-Peer communications on devices on different networks

I am struggling to sort through the options for building an application that can send and receive messages peer-to-peer to any device connected to any network anywhere in the world. I know I will likely need a relay server to handle DNS and I will also need to handle changing IP addresses as mobile devices move around and their IP address changes. What I am puzzled about is I've read up on Bonjour and on the Network framework and it appears to me (and I may be wrong) that these capabilities only support either devices on the same local network, or devices that are in close proximity to one another. For an iOS application, what is the recommended service or framework to use to build the send/receive functionality in the app? Is it even possible? Thanks!

I've read up on Bonjour and on the Network framework and it appears to me (and I may be wrong) that these capabilities only support either devices on the same local network, or devices that are in close proximity to one another.

Correct.

This is a hard problem in general. As well as the things you’ve mentioned, you need to consider NAT.

Have a look at this to get started: https://en.wikipedia.org/wiki/STUN

The difficulty of true peer-to-peer communication on the Internet leads many to use a centralised server or some other alternative.

Peer-to-Peer communications on devices on different networks
 
 
Q