Book Image

Socket.IO Real-time Web Application Development

By : Rohit Rai
Book Image

Socket.IO Real-time Web Application Development

By: Rohit Rai

Overview of this book

<p>The expectations of users for interactivity withweb applications have changed over the past few years. No more does the user want to press the refresh button to check if new messages have arrived in their inbox; people expect to see updates in their applications in real-time. Mass multiplayer online games have given up the requirement of plugins and are built entirely in JavaScript. Socket.io enables you to build these highly interactive applications that work cross-browser.<br /><br />"Socket.io Real-time Web Application Development" is a guide to building, deploying, and scaling highly interactive real-time web applications using socket.io. This book will guide you through the building of a chat system using Node.js and socket.io, helping you get familiar with various features of the framework. Going further it will empower you to deploy and scale your applications in production.<br /><br />Introducing web application development with Node.js, this book walks you through developing of a full-fledged chat system built with socket.io and introducing all the concepts of socket.io and its usage in the process.<br /><br />It introduces you to the different approaches of bidirectional communication between the browser and the web server and will show you how socket.io abstracts all this for you to provide a single unified and uniform API for messaging and eventing to develop cross-browser applications. It explains how to authenticate your users, segregate the communication to channels, build chat rooms, and handle and scale sessions. It explains the mechanics behind socket.io and it also introduces you to what is involved in deploying the application to production and the intricacies involved in scaling it. <br /><br />This book will introduce you to all that is needed in browser-server communication to develop the next generation of interactive applications and games.</p>
Table of Contents (16 chapters)
Socket.IO Real-time Web Application Development
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Client events


In this section we will get to know some client-side events.

connect

The connect event is emitted when the socket is connected successfully:

socket.on('connect', function () {})

connecting

The connecting event is emitted when the socket is attempting to connect with the server:

socket.on('connecting', function () {})

disconnect

The disconnect event is emitted when the socket is disconnected:

socket.on('disconnect', function () {})

connect_failed

The connect_failed event is emitted when socket.io fails to establish a connection to the server for reasons such as when none of the transports work or authorization failed:

socket.on('connect_failed', function () {})

error

The error event is emitted when an error occurs and it cannot be handled by the other event types:

socket.on('error', function () {})

message

The message event is emitted when a message sent with socket.send is received:

socket.on('message', function (<message>, <ack_callback>) {})

Here, message is the sent message and ack_callback is an optional acknowledgment function.

reconnect

The reconnect event is emitted when socket.io successfully reconnects to the server:

socket.on('reconnect', function () {})

reconnecting

The reconnecting event is emitted when the socket is attempting to reconnect with the server:

socket.on('reconnecting', function () {})

reconnect_failed

The reconnect_failed event is emitted when socket.io fails to reestablish a working connection after the connection was dropped:

socket.on('reconnect_failed', function () {})