TURN Server Setup

When and why is this needed?

RunPod and many other cloud providers have restrictive network policies that can block direct streaming connections. The TURN server acts as a trusted intermediary that can relay the streaming data between your local machine and the server. Additionally, if direct UDP connections fail (common with corporate/cloud environments), the TURN server can fall back to TCP, making the connection more reliable. To use a TURN server in this set up, follow the steps below:

  1. Create a Twilio account at twilio.com
  2. Get credentials from console.twilio.com
  3. Take note of your ACCOUNT SID and AUTH TOKEN for use in the next section of this document

Alternatively you can use tunneling with SSH

Setting up SSH Tunneling

Tunnel to open up UDP connection

  • On the remote server (remote_host), run:
socat TCP4-LISTEN:4321,fork UDP4:127.0.0.1:5678
  • On the local machine, Open an SSH tunnel
 ssh -L 4321:localhost:4321 {remote_user@remote_host and other params from Runpod ssh cmd}
  • On the local machine, run
socat UDP4-LISTEN:1234,fork TCP4:127.0.0.1:4321

Traffic sent to localhost:1234 on the local machine will be forwarded over the SSH tunnel and will reach 127.0.0.1:5678 on the remote server

Open another terminal, ssh into the remote SSH terminal:

  • You should find “SSH over exposed TCP” value in Runpod
  • Copy that command, and add -L 8889:localhost:8889
    • For example: ssh -L 8889:localhost:8889 root@{runpod_ip} -p 16974 -i ~/.ssh/id_ed25519

8889 is the port that ComfyStream is listening on at the remote server