Peer to peer (P2P) is a connection that enables two or more devices to share data through the internet without the help of an intermediary server. This architecture is widely preferred in real time applications such as online games, voice and video conference and file sharing as it is very helpful in reducing delay and allowing true peer to peer communication. But getting them to connect directly is not always easy and virtually impossible if both the devices are connected with NAT routers.

WebRTC or Web Real-Time Communication is an open-source project that aims to provide the methodology for creating channels of real-time P2P communication between browsers and/or apps. It supports direct transfer of audio, video and data in real time so it plays a critical role in such services like video conferencing, online collaboration, peer to peer file transfers.

How WebRTC Sets Up Peer to Peer Connections

To enable direct connections between devices, WebRTC uses a combination of the listed technologies below:

  • STUN (Session Traversal Utilities for NAT): It can be used to find out the external IP address, through which connection is possible after passing through NAT
  • ICE (Interactive Connectivity Establishment): Oversees the coordination in acquiring and checking different network links to identify the best proper connection
  • TURN (Traversal Using Relays around NAT): However, a direct connection between two peers cannot be formed in some cases (for example one peer is behind the Symmetric NAT) so the data are transmitted through the TURN servers

WebRTC aims at direct connections, though the existence of such restrictive NAT types as Symmetric NAT makes P2P communication impossible without a TURN server to act as a relay. This creates some additional burden, but it guarantees that the messaging can go on in any case.

Communication is now an essential part of many modern applications, which requires the use of WebRTC to ensure the use of applications with low latency and reliable security. However, to be able to reach another node, a proper connection configuration raises a possibility to build direct P2P connection, and therefore, achieve better network performance avoiding relay servers as much as possible.