Skip to Content
High Performance Browser Networking
book

High Performance Browser Networking

by Ilya Grigorik
September 2013
Intermediate to advanced content levelIntermediate to advanced
398 pages
10h 52m
English
O'Reilly Media, Inc.
Book available
Content preview from High Performance Browser Networking

Chapter 17. WebSocket

WebSocket enables bidirectional, message-oriented streaming of text and binary data between client and server. It is the closest API to a raw network socket in the browser. Except a WebSocket connection is also much more than a network socket, as the browser abstracts all the complexity behind a simple API and provides a number of additional services:

  • Connection negotiation and same-origin policy enforcement

  • Interoperability with existing HTTP infrastructure

  • Message-oriented communication and efficient message framing

  • Subprotocol negotiation and extensibility

WebSocket is one of the most versatile and flexible transports available in the browser. The simple and minimal API enables us to layer and deliver arbitrary application protocols between client and server—anything from simple JSON payloads to custom binary message formats—in a streaming fashion, where either side can send data at any time.

However, the trade-off with custom protocols is that they are, well, custom. The application must account for missing state management, compression, caching, and other services otherwise provided by the browser. There are always design constraints and performance trade-offs, and leveraging WebSocket is no exception. In short, WebSocket is not a replacement for HTTP, XHR, or SSE, and for best performance it is critical that we leverage the strengths of each transport.

Note

WebSocket is a set of multiple standards: the WebSocket API is defined by the W3C, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Networking Fundamentals

Networking Fundamentals

Gordon Davies
Networking and Kubernetes

Networking and Kubernetes

James Strong, Vallery Lancey
Kubernetes: Up and Running, 3rd Edition

Kubernetes: Up and Running, 3rd Edition

Brendan Burns, Joe Beda, Kelsey Hightower, Lachlan Evenson

Publisher Resources

ISBN: 9781449344757Errata Page