by Pivec Labs
TURN Server Setup Voice & Video

TURN Server Setup

Set up the TURN server that carries calls when players can't reach each other directly — with the wizard, or by hand.

01

Why a TURN server#

WebRTC first tries to connect players directly. That works on a LAN and between most home connections, but fails behind strict NATs, many mobile networks and company firewalls. A TURN server relays the media for exactly those players; everyone else still connects directly. NetCrafter Live uses coturn, the standard open-source TURN server, on a Linux machine you control — the machine running SmartFoxServer is a good choice.

Logins are time-limited (coturn's use-auth-secret): coturn and your zone extensions share one secret; the extension hands each player a login valid for a limited time (24 h by default, renewed automatically). The secret never leaves your server and never appears in a game build.

02

The TURN Server Wizard#

Open Tools → Pivec Labs → NetCrafter Pro → Live → TURN Server Wizard. Like NetCrafter Relay's wizard it never connects to your server itself: every step shows the exact command, you run it in your own terminal (your own SSH login) and paste the output back.

  1. Target — server address, SSH port and user.
  2. Pre-flight — log in, copy install-coturn.sh to the server (the wizard gives you the scp line), and check the OS (Ubuntu/Debian with systemd).
  3. Detect — a read-only check: is coturn installed, does something else already use it, where is SmartFoxServer, what is the public IP.
  4. Install — one command installs/configures coturn, writes NetCrafterLive.properties into every SmartFoxServer extension folder and restarts SFS3.
  5. Verify — tests a real time-limited login against coturn and checks SmartFoxServer's log for the Live "ready" line.
  6. Finish — saves the TURN host and ports into Live Server, so local Deploys write the same settings.

The secret

The wizard uses the shared secret from Live → Live Server (it creates one if there is none). It is stored in UserSettings/NetCrafterLiveServer.json — outside Assets/, so it is never part of a build or a package export. Use Check: is the secret anywhere under Assets/? in that tab if in doubt.

03

Sharing a server with NetCrafter Relay#

If the machine already runs coturn for something else — for example NetCrafter Relay, which uses fixed logins on port 3478 — the wizard detects it and installs a separate instance instead:

Existing coturn (e.g. Relay)NetCrafter Live instance
Servicecoturnnetcrafter-live
Config/etc/turnserver.conf (untouched)/etc/turnserver-netcrafter-live.conf
Port34783479 (TLS 5350 if used)
Relay portsits own range50000–65535
Loginsits owntime-limited (use-auth-secret)

Nothing of the existing setup is changed, and each product can be updated or removed independently.

04

Installing by hand#

Live/ServerTools/install-coturn.sh is what the wizard runs; you can run it yourself:

bash
scp install-coturn.sh root@your.server:~/
ssh root@your.server
sudo bash ~/install-coturn.sh --secret <64 hex chars> --turn-host your.server \
     --sfs3-dir /opt/sfs3/SmartFoxServer3 -y && sudo systemctl restart sfs3
OptionMeaning
--secretShared secret (required). Same value as live.turn.secret.
--instance NAMEcoturn = the system service; any other name = a separate instance.
--port / --min-port / --max-portListening port (3478) and relay port range (49152–65535).
--tls-port --tls-cert --tls-keyOptional TLS (e.g. 5349 with Let's Encrypt fullchain.pem / privkey.pem). Gets through networks that block UDP.
--turn-hostName or IP players connect to (default: detected public IP).
--public-ip / --private-ipFor cloud servers behind 1:1 NAT, if detection is wrong.
--sfs3-dirWrites NetCrafterLive.properties into every extension folder that has a JAR.
--max-call-size --max-viewers --ttlWritten to the properties file.
--forceAllow replacing a /etc/turnserver.conf that has static user= logins.

The script never enables a firewall. It hardens coturn (no CLI, no relaying to private/loopback addresses, quotas, TLS 1.2+ only) and prints NCL_* summary lines.

05

NetCrafterLive.properties#

Each zone extension reads NetCrafterLive.properties from its own extension folder when SmartFoxServer starts:

properties
live.turn.secret=<same as coturn's static-auth-secret>
live.turn.host=turn.example.com
live.turn.port=3478
live.turn.tlsPort=0
live.turn.ttlSeconds=86400
live.maxCallSize=6
live.maxViewers=8
  • Local SFS3: Code → Server Code → Deploy writes it next to the JAR; Live → Live Server → Write NetCrafterLive.properties to the local SFS3 updates all Definitions at once.
  • Remote SFS3: the wizard writes it, or use Copy command for a remote server in the Live Server tab and paste it into an SSH session.
  • Restart SmartFoxServer after changing it. No file / no secret: Live still works for direct connections and warns once that TURN is unavailable.
06

Firewall#

PortProtocolWhy
3478 (or 3479)UDP + TCPTURN/STUN
5349 (or 5350)TCPTURN over TLS (only if enabled)
49152–65535 (or 50000–65535)UDPrelayed media
9977TCP (+UDP)SmartFoxServer (already open for your game)

If ufw is active the script adds these rules; it never turns a firewall on. Your hosting provider's firewall (security group) must allow them too.

07

Windows development servers#

coturn has no native Windows build. For LAN tests you don't need TURN at all. To test the relay path on Windows, run coturn in Docker (docker run -d --network host coturn/coturn -c /etc/turnserver.conf with a config like the one the script writes) or inside WSL2 with the script itself.

08

Bandwidth#

In a call every player uploads one copy of their video per other player. NetCrafterLiveCall adapts automatically (1 other player: 1500 kbps, 2–3: 800 kbps, 4–5: 500 kbps; 24 fps) unless you set maxVideoBitrateKbps.

PlayersUpload per player (video + voice)Download per player
2≈ 1.5 Mbps≈ 1.5 Mbps
4≈ 2.5 Mbps≈ 2.5 Mbps
6≈ 2.7 Mbps≈ 2.7 Mbps

A broadcast host uploads one stream per viewer (default cap 1200 kbps each). The TURN server only carries the pairs that can't connect directly; size its network for those.

09

Clocks#

Time-limited logins contain an expiry time. coturn and SmartFoxServer must have correct clocks (NTP) — automatic when both run on the same machine.