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
TheICEGatherer collects local network addresses and contacts STUN/TURN servers:
icegatherer.go
ICETransport
TheICETransport 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
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
icegatherer.go
ICE Connection States
The ICE connection goes through several states:icetransport.go
Monitoring ICE State
Adding Remote Candidates
icetransport.go
Selected Candidate Pair
Once connectivity is established, you can inspect the selected candidate pair:icetransport.go
ICE Restart
Restart ICE to recover from connection failures:icetransport.go
Advanced ICE Configuration
Setting ICE Credentials
Network Interface Filtering
ICE Timeouts
Troubleshooting ICE
Diagnostic Tips
- Check gathered candidates:
- Monitor connection states:
- Enable ICE agent logging:
Next Steps
Media Streams
Learn about sending and receiving media
Data Channels
Explore bidirectional data transfer