Chapter 5. Transcending AJAX: Using WebSockets

In this chapter we will cover:

  • Creating a WebSocket server
  • Seamless fallbacking with socket.io
  • Callbacks over socket.io transport
  • Creating a real-time widget

Introduction

HTTP was not made for the kind of real-time web applications that many developers are creating today. As a result, all sorts of workarounds have been discovered to mimic the idea of bi-directional, uninterrupted communication between servers and clients.

WebSockets don't mimic this behavior, they provide it. A WebSocket works by stripping down an HTTP connection so it becomes a persistent TCP-like exchange, thus removing all the overhead and restrictions HTTP introduces.

The HTTP connection is stripped (or rather upgraded) when both the ...

Get Node Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.