Troubleshooting: direct or relayed, and why
Connectivitizer first tries to connect the two endpoints directly (peer to peer, over UDP). When that does not work in time, the session goes through the relay instead. Both ways are end-to-end encrypted: the relay forwards bytes it cannot read. The difference is the route, the latency, and the plan's relay allowance, which only relayed traffic counts against.
The SDKs and cz do everything an endpoint can do for a direct session by themselves: they offer their local addresses, their IPv6 addresses and their public address, and punch through the routers. What keeps a session from being direct is almost always the network. This page says which part of it, and what helps.
For errors that stop a session altogether (DEVICE_OFFLINE, FORBIDDEN, E2E_SHARED_KEY_MISMATCH, …) see Error codes.
How do I see whether a session was direct, and why not?
Web app, Connections: every session shows Direct or Relayed. A relayed one says why, for example "Not direct: The two endpoints could not reach each other directly in time."
SDKs:
session.info.modeisdirectore2e-relay(in .NETsession.Info.Mode). A direct session'speerAddressis where the peer was reached; an IPv6 address is written in square brackets.directFailureReasonholds the reason code of a relayed one (the table below).cz:
cz connectprints the mode, the peer address and, for a relayed session, the reason.The app: Account › Connection › Share the connection log gives the log of the current app run: for each session the addresses both sides announced, the probes sent and received, and the path taken. It contains network addresses, no keys.
A device's log (.NET, Node.js, Python, JVM, ESP32; the log callback of the agent): for each session, lines starting with
direct:say which addresses the device announced, which the peer announced, where the first probe came from, and, when no path was found, how many probes it sent and received.ESP32: the library's log (
Connectivitizer.setLog(Serial)) prints, per session, the addresses the device offers, the addresses the app offers, and then either where the app was reached or why there is no direct path:Terminalsession …: offering "udp":["192.168.2.176:54249","[2001:db8:1:…]:54249","203.0.113.7:54249"],"nat":"cone"} session …: the app offers "udp":["[2001:db8:2:…]:50957","198.51.100.24:17967"],"nat":"symmetric"} session … established with Example app (direct, shared-key, app at [2001:db8:2:…]:50957, announced)announcedmeans the app was reached at an address it offered;learnedmeans at an address its packets came from that it could not offer itself (see "From mobile data" below). Without a direct path the line before "established" readsno direct path, using the relay (probes received: N, from an unannounced address: …): 0 probes means nothing of the app's got through to the device.
Which address was used: Wi-Fi, IPv6, or learned?
| The address the peer was reached at | Path |
|---|---|
| a local address (192.168.x.x, 10.x.x.x, …) | inside the same network |
in square brackets, [2003:…] | over IPv6 |
a public IPv4 address, marked announced | through both routers by hole punching |
marked learned | at an address the peer's NAT chose, which the peer could not announce (a symmetric NAT, typical for mobile data over IPv4) |
What do the reasons mean?
| Reason | Meaning | What usually helps |
|---|---|---|
policy_relay_only | The service's path policy in the web app is relay-only. | Change the policy, if you want direct sessions. |
peer_no_direct_support | The other side does not do peer to peer: an ESP32 with setPeerToPeer(false), an endpoint with direct connections switched off (disableDirect), or a React Native app running in Expo Go, which has no UDP. | Enable it on that side; run the app as a development build instead of in Expo Go. |
stun_unreachable | The endpoint could not ask any STUN server for its public address. | Check that UDP to the platform's STUN ports (3478, 3479) gets out of that network. |
udp_blocked_local, udp_blocked_remote | UDP does not get out of that side's network at all. Typical for company, hotel and some guest networks. | Another network; nothing to do on the endpoint. |
symmetric_nat_both | Both sides are behind a NAT that uses a new public port for every destination. Hole punching cannot get through two of those. | One side on another network, or IPv6 on both. |
probe_timeout | Both sides knew their addresses, but the punching packets did not get through within 3 seconds. See the questions below. | Depends on the case. |
tcp_unreachable | (cz and .NET only) a direct TCP connection to the offered address failed. | Check the port forwarding behind --public-tcp. |
Both sides are in the same Wi-Fi, and it still goes through the relay
Inside one network, the two sides reach each other by their local addresses (192.168.x.x and the like). Check:
- Wi-Fi isolation. Guest networks, and some mesh or IoT networks, do not let two Wi-Fi clients talk to each other. An ESP32's log then shows "probes received: 0". Put both into the main network, or allow traffic between clients in the router.
- Both sides must be in the same network, not just the same router. A phone on mobile data while its Wi-Fi is off, or a PC on a separate VLAN, is not in the same network.
- A VPN on the phone or PC. VPNs that leave the local network alone (for example NordVPN Meshnet) do not matter. A VPN that sends all traffic through the tunnel, local network included, makes the device unreachable, so the session is relayed.
From mobile data: when is it direct?
Over IPv4, mobile networks almost always put phones behind carrier-grade NAT, and that NAT usually maps every destination to a different public port ("symmetric"). The address the phone learns from the STUN server is then not the address the device would see, and a home router lets in only packets from addresses the device has itself sent to.
Two things get around it, and the SDKs use both by themselves:
- IPv6. IPv6 has no NAT. If the phone has IPv6 on mobile data and the device has a global IPv6 address at home, both offer it, send to each other at the same time, and so open both firewalls. What the network has to provide:
- the router at home must hand out IPv6 to the home network (most do when the internet line has IPv6). An ESP32 switches IPv6 on by itself; its log then lists an address in brackets, like
[2001:db8:1:…]:54249; - the phone must have IPv6 on mobile data. The phone's browser can tell at test-ipv6.com.
- the router at home must hand out IPv6 to the home network (most do when the internet line has IPv6). An ESP32 switches IPv6 on by itself; its log then lists an address in brackets, like
- Learned addresses. When the phone's packets arrive at the device from an address the phone could not announce, the device may answer there. That helps when the home router lets in packets from the address the device itself sent to, whatever their port, which many routers do not.
When neither works, the session goes through the relay. The relay keeps the session end-to-end encrypted. It only costs latency and relay allowance.
On mobile data it was direct before, and now it is relayed
Both sides have IPv6, nothing changed at home, and sessions from mobile data still end with probe_timeout. The two logs then tell the same story from both ends: the device's log counts probes received from the phone, and the app's log says "received 0 probes and 0 answers". The phone's packets arrive at the device; nothing comes back to the phone.
In that case the phone's current mobile data connection does not deliver incoming IPv6 packets. A new connection does:
- Switch the phone's flight mode on, wait a few seconds, and switch it off again. The phone gets a new mobile data connection, with new addresses from the provider.
- Open the device again.
In the app, Account › Connection › Open the flight mode setting leads to the switch. Android does not let an app switch flight mode itself.
If it stays relayed after that, share the app's log (Account › Connection › Share the connection log) and compare it with the device's log as described above: the side that receives 0 probes is the side whose network keeps the packets out.
It works at home but not in the office, hotel or on public Wi-Fi
Such networks often block UDP entirely (udp_blocked_local), or allow only web traffic. That is not something the endpoints can change. The relay works there, because it uses an ordinary HTTPS/WebSocket connection.
Testing with an emulator
The Android emulator has a NAT of its own inside the PC. A device in the local network sees its packets coming from the PC's address, which the emulator does not announce, so sessions from the emulator to a device in your network are relayed. Test peer to peer on a real phone.
Is a relayed session less secure?
No. The relay forwards the encrypted end-to-end channel and cannot read it: with a shared key only the app and the device hold that key, with certificates only the two endpoints hold their private keys. What changes is the route and the plan's relay allowance.
Can I force direct connections?
Set the service's path policy in the web app to direct-only. A session that cannot be direct then fails with DIRECT_UNAVAILABLE instead of being relayed. That is useful for testing, rarely for daily use.
cz and the .NET library can additionally connect directly over TCP when one side has a forwarded port or a public address (--tcp-port and --public-tcp, see the cz guide). The other SDKs use UDP only.
Is it safe that a device answers at an address the app did not announce?
Yes, because of when it is allowed. Learned addresses are used only in sessions whose end-to-end layer authenticates the peer (a shared key, or certificates), and such a path counts as direct only after that handshake succeeded on it. Someone who offered a forwarder as a path would see only ciphertext; the handshake fails unless the real peer is at the other end.