Candidats ICE et connectivité
Explorez les candidats ICE, la manière dont ils représentent les adresses réseau et la façon dont ICE facilite la recherche du meilleur chemin pour une connexion de pair à pair.
Candidats ICE et connectivité est une leçon Real-Time Streaming Systems (WebRTC + Live Data) gratuite sur CoddyKit. Ceci est la leçon 3 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Real-Time Streaming Systems (WebRTC + Live Data), et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Real-Time Streaming Systems (WebRTC + Live Data) comprend 4 leçons au total.
Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.
ICE: The Connectivity Finder
ICE stands for Interactive Connectivity Establishment. It's a crucial framework in WebRTC that helps establish direct connections between peers, even when they are behind tricky networks like NATs or firewalls.
Think of ICE as a smart detective. It finds all possible routes for two people to talk directly and then picks the best one.
Overcoming Network Barriers
Many devices connect to the internet through routers that use NAT (Network Address Translation) or have firewalls. These act like security guards, often blocking direct incoming connections.
- NAT: Hides private network IPs behind a single public IP.
- Firewalls: Block unauthorized access.
Without ICE, establishing a direct peer-to-peer connection in such environments would be nearly impossible.
What Are ICE Candidates?
An ICE Candidate is essentially a potential network address and port where a peer can be reached. Each peer collects multiple candidates representing different ways it can communicate.
These candidates are like different phone numbers or addresses you might have: your home number, your work number, a friend's number where you can be reached, etc. ICE tries them all.
Types of ICE Candidates
There are three main types of ICE candidates:
- Host Candidates: These are the peer's actual local IP addresses. They work best for direct connections within the same local network.
- Server Reflexive Candidates: Obtained from a STUN server. This is your public IP address and port as seen by an external server, helping peers behind NATs find each other.
- Relayed Candidates: Obtained from a TURN server. If direct connection isn't possible, a TURN server relays all traffic. This is the last resort.
Gathering Candidates: The Process
When a WebRTC connection is initiated, each peer's browser (the WebRTC agent) starts collecting ICE candidates. It actively queries the local network, STUN servers, and potentially TURN servers to find all possible communication paths.
This collection process happens continuously in the background as the RTCPeerConnection is being set up.
Code: Listening for Candidates
In JavaScript, you listen for icecandidate events on your RTCPeerConnection object to get these candidates. Each event provides a new candidate to share with the remote peer via your signaling server.
const pc = new RTCPeerConnection();
pc.onicecandidate = (event) => {
if (event.candidate) {
console.log("New ICE candidate found:");
console.log(event.candidate.candidate);
// Send this candidate to the remote peer via signaling server
} else {
console.log("ICE candidate gathering complete.");
}
};
console.log("Listening for ICE candidates...");
// Note: This snippet requires a full browser WebRTC context to run
// and produce actual candidates. It's for demonstration.Exchanging Candidates: Signaling
Once candidates are gathered, they must be exchanged between the two peers. This happens through your signaling server, the same server used to exchange SDP offers and answers.
- Each peer sends its collected candidates to the signaling server.
- The signaling server forwards these candidates to the other peer.
This process is often called "trickle ICE" because candidates are sent as they are found, rather than waiting for all of them.
The Connectivity Check
After exchanging candidates, ICE begins its connectivity checks. Both peers try to establish connections using every possible pair of local and remote candidates. This involves sending small "STUN binding requests" to test reachability.
ICE then prioritizes and selects the most efficient and reliable path. It prefers direct host connections, then STUN-relayed public IPs, and finally TURN-relayed connections.
Quick Check: ICE Candidate Types
Which type of ICE candidate is obtained with the help of a STUN server to reveal a peer's public IP address?
Recap: ICE in Action
In this lesson, you learned about ICE Candidates and how they enable WebRTC to establish peer-to-peer connections across diverse networks.
- ICE candidates are potential network addresses.
- They come in types: Host, Server Reflexive (STUN), and Relayed (TURN).
- Peers gather and exchange these candidates via a signaling server.
- ICE then performs connectivity checks to find the best possible path for direct communication.
ICE is the unsung hero ensuring your real-time calls find a way through the internet's complexities!
Apprends Real-Time Streaming Systems (WebRTC + Live Data) avec un tuteur IA — gratuit
Écris et exécute du vrai code dans ton navigateur, obtiens de l'aide instantanée d'un tuteur IA disponible 24h/24, et reprends là où tu t'es arrêté sur le web ou dans l'app.
- Cours
- 12
- Leçons
- 48
Questions Fréquemment Posées
La leçon « Candidats ICE et connectivité » est-elle gratuite ?
Oui — le texte complet de « Candidats ICE et connectivité » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Real-Time Streaming Systems (WebRTC + Live Data), passe à CoddyKit PRO. Le cours Real-Time Streaming Systems (WebRTC + Live Data) comprend 4 leçons au total.
Qu'est-ce que j'apprendrai dans « Candidats ICE et connectivité » ?
Explorez les candidats ICE, la manière dont ils représentent les adresses réseau et la façon dont ICE facilite la recherche du meilleur chemin pour une connexion de pair à pair. Tu pratiques Real-Time Streaming Systems (WebRTC + Live Data) avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.
Dois-je avoir de l'expérience pour commencer Real-Time Streaming Systems (WebRTC + Live Data) ?
Aucune expérience préalable n'est requise. Real-Time Streaming Systems (WebRTC + Live Data) sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 3 sur 4.
Combien de temps prend la leçon « Candidats ICE et connectivité » ?
La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.
Peux-tu écrire et exécuter du code dans cette leçon Real-Time Streaming Systems (WebRTC + Live Data) ?
Oui. Chaque leçon Real-Time Streaming Systems (WebRTC + Live Data) inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.
Toutes les leçons de ce cours
- Rôle des serveurs de signalisation
- SDP : protocole de description de session
- Candidats ICE et connectivité
- Renégociation et état de la connexion