You are previewing Node for Front-End Developers.

Node for Front-End Developers

Cover of Node for Front-End Developers by Garann Means Published by O'Reilly Media, Inc.
O'Reilly logo

Real-Time Communication

When Ajax showed up, it ushered in a new way of thinking about web requests. It was no longer necessary to request entire pages—we could communicate with the server in pure data. The server still had to wait for requests from the client, however. A client could poll the server for updates, but there was no way for the server to push new information to the client. The WebSockets API is part of the large collection of new standards being developed under the name HTML5, and allows the server and the client to open a bidirectional connection so that data can be pushed back and forth whenever necessary.

WebSockets and the various fallbacks used to mimic them aren’t a technology specific to Node, but they make a very tidy fit. WebSockets are controlled with JavaScript, and the way they work looks an awful lot like the type of event handling we’re used to in JavaScript. As we move toward applications that anticipate users’ needs, perform non-essential operations in the background and report status, or just offer users a window into what’s happening on the server as it happens, WebSockets become increasingly necessary. One or two real-time features might be easy enough to handle with long polling or some other method, but an entire real-time application warrants the use of the only truly appropriate technology.

One of the more popular and mature Node modules is Socket.IO, which wraps up WebSockets and a selection of fallbacks and exposes the functionality via an API ...

The best content for your career. Discover unlimited learning on demand for around $1/day.