We have published a previous post about WebRTC and WebRTC servers without any technical details. Unlike the first post, in this second part of our WebRTC blog post series, we will introduce the WebRTC basics and technical terms: SDP, ICE, STUN Server, TURN Server, RTP, and Signalling.

I want to explain WebRTC concept with an example. Let Client-A and Client-B are two pairs who want to communicate via WebRTC. Assume that Client-A starts the communication.

WebRTC (Web Real-Time Communication)

WebRTC is a set of technologies that enables peer to peer duplex real-time communication between browsers even behind NAT addresses.

In our example, WebRTC is the technology to establish communication between Client-A and Client-B.

SDP (Session Description Protocol)

SDP is a simple string based protocol and it is to share supported codecs between browsers.

In our example,

  • Client-A creates its SDP ( called offer) and saves as local SDP then shares it with Client-B.
  • Client-B receives the SDP of Client-A and saves it as remote SDP.
  • Client-B creates its SDP (called answer) and saves as local SDP then shares it with Client-A.
  • Client-A receives the SDP of Client-B and saves it as remote SDP.

Signalling Server is responsible for these SDP transfer between peers.

Let assume Client-A may support H264, VP8 and VP9 codecs for video, Opus and PCM codecs for audio. Client-B may support only H264 for video and only Opus codec for audio. For this case, the Client-A and Client-B will use H264 and Opus for codecs. If there are no common codecs between peers, peer to peer communication cannot be established.

ICE (Interactivity Connection Establishment)

ICE is the magic that establishes WebRTC connection between peers even if they are behind NAT/Firewall devices.

STUN Server (Session Traversal Utilities for NAT)

STUN Server is responsible to get all the addresses of a machine. For example, our computers generally have one local address in the 192.168.0.0 network and there is a second address we see when we connect to www.whatismyip.com, this IP address is actually the Public IP address of our Internet Gateway(modem, router, etc.) so let’s define STUN server; STUN servers let peers know theirs Public and Local IP addresses.

Google provides a free STUN server (stun.l.google.com:19302).

WebRTC Direct Connection between Peers Direct connection between peers[/caption]

TURN(Traversal Using Relays around NAT) Server

Sometimes, addresses got from STUN server cannot be used to establish for peer to peer connection between peers because of NAT/Firewall. In this case, data relays over TURN Server

WebRTC Basics & WebRTC Components 1 Connection over TURN server between peers

In our example,

  • Client-A finds out their local address and public Internet address by using STUN server and sends these address to Client-B through Signalling Server. Each address received from STUN server is an ICE candidate.
  • Client-B does the same, gets local and public IP addresses from STUN server and sends these addresses to Client-A through Signalling Server.
  • Client-A receives Client-B’s addresses and tries each IP addresses by sending special pings in order to create the connection with Client-B. If Client-A receives a response from any IP addresses, it puts that address in a list with its response time and other performance credentials. At last Client-A choose the best addresses according to its performance.
  • Client-B does the same in order to connect to Client-A

RTP (Real Time Protocol)

RTP is a mature protocol for transmitting real-time data on top of UDP. Audio and Video are transmitted with RTP in WebRTC. There is a sister protocol of RTP which name is RTCP(Real-time Control Protocol) which provides QoS in RTP communication. RTSP(Real-time Streaming Protocol) uses RTP protocol as well in data communication.

Signaling Server

The last part is the Signalling Server which is not defined in WebRTC. As mentioned above, Signalling Server is used to send SDP strings and ICE Candidates between Client-A and Client-B. Signalling Server also decides which peers get connected to each other. WebSocket technology is the preferred way in Signalling Servers for communication.

WebRTC Signaling message sequence

Signaling message sequence

In this post, we have introduced the basic components and terms under WebRTC technology without coding details. We will continue to WebRTC blog post series with Peer-To-Peer connection establishment in details.

In order to get more details about WebRTC, you can check this great post out as well.

Categories: Tutorial