Skip to main content

What is ICE?

Interactive Connectivity Establishment (ICE) is a framework for establishing peer-to-peer connections across NATs and firewalls. It combines multiple techniques (STUN, TURN) to find the best path for communication.

ICE Components in Pion

Pion WebRTC implements ICE through several components:

ICEGatherer

The ICEGatherer collects local network addresses and contacts STUN/TURN servers:
icegatherer.go

ICETransport

The ICETransport manages the connectivity checking process:
icetransport.go

ICE Candidate Types

Pion supports all standard ICE candidate types:

Host

Local IP addresses discovered on the device’s network interfaces.

Server Reflexive (srflx)

Public IP address as seen by a STUN server.

Peer Reflexive (prflx)

Discovered during connectivity checks.

Relay

Address allocated on a TURN server for relaying traffic.

ICECandidate Structure

icecandidate.go

Gathering Candidates

Basic Gathering

The gathering process from the source:
icegatherer.go

ICE Gathering States

1

New

Gatherer has been created but not started.
2

Gathering

Actively collecting candidates from network interfaces and servers.
3

Complete

All candidates have been gathered.

Configuring ICE Servers

STUN Server

TURN Server

Multiple Servers

TURN servers are used as a fallback when direct peer-to-peer connections fail. They relay all media traffic, so they can be expensive to operate.

ICE Transport Policies

How the policy is applied:
icegatherer.go

ICE Connection States

The ICE connection goes through several states:
icetransport.go

Monitoring ICE State

Adding Remote Candidates

icetransport.go
Usage:

Selected Candidate Pair

Once connectivity is established, you can inspect the selected candidate pair:
icetransport.go
Monitor selected pair changes:

ICE Restart

Restart ICE to recover from connection failures:
The restart implementation:
icetransport.go

Advanced ICE Configuration

Setting ICE Credentials

Network Interface Filtering

ICE Timeouts

Troubleshooting ICE

Common ICE connection failures:
  • Restrictive firewalls blocking UDP
  • No TURN server configured for relay fallback
  • Symmetric NAT requiring TURN
  • IPv6 connectivity issues

Diagnostic Tips

  1. Check gathered candidates:
  1. Monitor connection states:
  1. Enable ICE agent logging:

Next Steps

Media Streams

Learn about sending and receiving media

Data Channels

Explore bidirectional data transfer