NATs provide a device with an IP address for use within a private local network, but this address can't be used externally. Without a public address, there's no way for IoChat clients to communicate. To get around this problem IoChat uses STUN and TURN.

IoChat tries to set up direct communication between peers over UDP using STUN. If that fails, it resorts to TCP. If that fails, the TURN server is used as a fallback, relaying data between endpoints.


The STUN server should be accessible on the public internet and has one simple task: check the IP:port address of an incoming request from the IoChat application running behind a NAT and send that address back as a response. In other words, IoChat uses a STUN server to discover its IP:port from a public perspective. This process enables the client to get a publicly accessible address for itself, and then pass that on to another peer via the signaling component, in order to set up a direct link. The STUN server doesn't have to do or store much, so a relatively low specification STUN server can handle a large number of requests.