WebRTC and WebSockets are powerful technologies for real-time voice and video communication, but they have slightly different use cases. While WebRTC is best suited for direct peer-to-peer communication, WebSockets is more appropriate for multi-user applications.

What is WebSockets?

WebSocket is a protocol that enables an application on a user’s computer to establish a two-way communication with a server. In WebSockets, both the client and server are able to send and receive messages at the same time.

Compare that with traditional HTTP systems, which most websites use to send and receive information. In HTTP, clients must initiate requests, and the server can’t initiate requests independently. Because of this, the only way for clients to get updated information is to send a new request to the server. For example, if you’re chatting with a friend in a messaging app, you might send a message to the server, but then your computer must send further requests to the server to check for responses.

Naturally, with voice and video interactions, clients must continually send and receive information in real time. HTTP isn’t suitable for this type of task. That’s where WebSocket comes in, enabling two-way communication that’s supported by almost every modern browser.

Making a WebSocket connection starts with an HTTP request. The client starts by sending a “handshake” request, specifying that it wants to open up a WebSocket connection. If the server is capable of starting a WebSocket connection, it sends a successful handshake response, and the protocol switches from HTTP to WebSockets.

Once the connection is established, WebSockets sends messages using a TCP connection to ensure that packets of information are reliably delivered from one computer to another.

What is WebRTC?

Another powerful technology for voice and video connections is WebRTC — short for web real-time communication. Developed in 2011 by Google, WebRTC enables communication between users without the need to download plugins or install apps.

WebRTC is a free, open-source project available on most browsers and operating systems, including Chrome, Firefox, Safari, and Edge. Tech-focused brands have used WebRTC to offer a variety of voice and video capabilities, such as making video calls from directly within a website.

Unlike WebSockets, WebRTC is a peer-to-peer protocol which enables direct communication between browsers. Typically, individual computers sit on private networks that don’t have a public-facing IP address. Private networks rely on network access transversal (NAT) devices to translate private IP addresses into public IP addresses. 

WebRTC negotiates direct connections between computers using STUN (Session Traversal Utilities for NAT) and TURN (Traversal Using Relays around NAT) servers. By making a request to a STUN or TURN server, your computer can determine your public-facing IP address and let other computers know how to contact you. Other computers can do the same by making STUN or TURN requests.

Once WebRTC knows your IP address, the next step is for your computer to initiate a connection with another computer. This process is known as “signaling.” WebRTC is flexible and allows for a number of protocols to be used for session negotiation, including Session Initiation Protocol (SIP) and COMET.

Choosing the right technology

WebSockets and WebRTC are both great for real-time voice and video, but their ideal use cases are slightly different. WebSocket connections run through a central server, making them better suited for situations in which more than two users will be involved in a conversation. But since WebSocket connections aren’t direct, they allow for less efficient streaming — which can negatively affect audio and video quality. For one-on-one use cases, WebRTC is preferable.

WebSockets use cases

WebSocket is an ideal candidate for real-time voice and video chat with more than two parties. Here are some ways developers are putting WebSockets to use:

Multiplayer gaming: WebSockets enable developers to build high-performance multiplayer games directly in the browser without the need for plugins. Once the initial connection is established, players can receive continuous streaming video without a perceptible lag, interact with the game, and talk with one another in real time, all through a central server.

Collaborative editing: For applications that support real-time collaborative editing, WebSocket is a natural solution. WebSockets empower developers to relay changes to shared documents, presentations or whiteboards in real time to all participants while enabling real-time voice conversations between multiple editors.

Video Conferencing: WebSockets give developers the tools to build video conferencing tools that can accommodate multiple participants. Once users have made the initial connection, audio and video is continuously streamed to other participants through a central server, enabling large numbers of participants to see and talk with one another in real time. A good example of this can be found in Symbl’s realtime websockets adapter for Amazon Chime video conferencing, which can be used to add conversation intelligence to video conferencing.

WebRTC use cases

WebRTC is a technology of choice for developers building one-on-one voice or video solutions. Here are a few examples:

Customer support: Many companies have built customer support solutions using WebRTC, creating virtual phone systems that enable support agents to receive calls online directly from their web browser.

Conversational assistants: Many of today’s virtual assistants use WebRTC to send and receive voice data. Amazon Alexa is one popular platform that uses WebRTC, enabling developers to take advantage of Amazon’s APIs to build Alexa support into WebRTC-compliant devices.

Telemedicine: Telemedicine is skyrocketing in popularity, with patient adoption rates rising by 33%. Major telemedicine providers like Teladoc use WebRTC to enable face to face remote video calls between patients and their doctors from directly within web browsers, without installing special software.

Additional reading

You can experiment with your own app using Symbl’s WebSocket based real-time API, which lets you push an audio stream in real-time and get the results back as soon as they’re available. Here’s where you can go to learn more:

Avatar photo
Eric Giannini
Lead Developer Evangelist & Advocate