Interactive Connectivity Establishment (ICE)

Library organizations

See Table of Contents below.

Introduction to ICE

Interactive Connectivity Establishment (ICE) is the ultimate weapon a client can have in its NAT traversal solution arsenals, as it promises that if there is indeed one path for two clients to communicate, then ICE will find this path. And if there are more than one paths which the clients can communicate, ICE will use the best/most efficient one.

ICE works by combining several protocols (such as STUN and TURN) altogether and offering several candidate paths for the communication, thereby maximising the chance of success, but at the same time also has the capability to prioritize the candidates, so that the more expensive alternative (namely relay) will only be used as the last resort when else fails. ICE negotiation process involves several stages:

  • candidate gathering, where the client finds out all the possible addresses that it can use for the communication. It may find three types of candidates: host candidate to represent its physical NICs, server reflexive candidate for the address that has been resolved from STUN, and relay candidate for the address that the client has allocated from a TURN relay.

  • prioritizing these candidates. Typically the relay candidate will have the lowest priority to use since it’s the most expensive.

  • encoding these candidates, sending it to remote peer, and negotiating it with offer-answer.

  • pairing the candidates, where it pairs every local candidates with every remote candidates that it receives from the remote peer.

  • checking the connectivity for each candidate pairs.

  • concluding the result. Since every possible path combinations are checked, if there is a path to communicate ICE will find it.

Using ICE transport

The ICE stream transport is a ready to use object which performs the above ICE operations as well as provides application with interface to send and receive data using the negotiated path.

Please see ICE stream transport on how to use this object.

Creating custom ICE transport

If the ICE stream transport is not suitable for use for some reason, you will need to implement your own ICE transport, by combining the ICE Session with your own means to send and receive packets. The ICE stream transport provides the best example on how to do this.


The ICE demo sample pjsip-apps/src/samples/icedemo.c demonstrates how to use ICE stream transport without using signaling protocol such as SIP. It provides interactive user interface to create and manage the ICE sessions as well as to exchange SDP with another ice_demo instance.

Also see PJNATH Samples and screenshots for other samples.