What are WebSockets?

What are WebSockets?

WebSockets are a standard protocol, built into web browsers and commonly used in Web, native mobile, and desktop application development. WebSockets allow bidirectional communication between client and server programs.

Developers use WebSockets to send data to and from a server over a relatively long-lived connection. Examples of the kinds of apps that typically use web sockets include online games, messaging programs, and data dashboards that continuously update.

Before the WebSockets was standardized, web developers generally used various kinds of HTTP polling to continuously send and receive data to and from a server. Native application developers often built their own, custom, mini-protocols. Being able to rely on the WebSockets standard is much better!

The WebSockets protocol is defined in RFC 6455, first drafted in 2008 and finalized in 2011.

WebSockets and Use Cases

Today, browser implementations and libraries in all major programming languages and development frameworks are stable, reliable, and interoperable. This makes developing with WebSockets generally quite simple. Experienced developers reach for WebSockets in a wide variety of contexts and for a wide variety of use cases.

One specialized use case that isn’t a good fit for WebSockets, however, is sending and receiving real-time audio and video data.

Most real-time applications use WebSockets to set up each connection and manage application state, and use WebRTC to send and receiv audio and video.

For more about the differences between WebSockets and WebRTC read this article.

References:

Want to learn more about WebRTC? Visit our community, developer resources, or our blog.