Socket.IO Cookbook

Book description

Over 40 recipes to help you create real-time JavaScript applications using the robust Socket.IO framework

About This Book

  • Create secure WebSocket connections and real-time mobile applications using Socket.IO
  • Devise efficient messaging systems between the server side and the client side
  • A step-by-step implementation guide to help you create elements of Socket.IO application

In Detail

Socket.IO is a JavaScript library that provides you with the ability to implement real-time analytics, binary streaming, instant messaging, and document collaboration. It has two parts: a client-side library that runs in the browser, and a server-side library for node.js. Socket.IO is event-driven and primarily uses the WebSocket protocol that allows us to emit data bi-directionally from the server and the client. Socket.IO.

This book is a complete resource, covering topics from webSocket security to scaling the server-side of a Socket.IO application and everything in between.

This book will provide real-world examples of how secure bi-directional, full-duplex connections that can be created using Socket.IO for different environments. It will also explain how the connection vulnerabilities can be resolved for large numbers of users and huge amounts of data/messages.

By the end of the book, you will be a competent Socket.IO developer. With the help of the examples and real-world solutions,you will learn to create fast, scalable, and dynamic real-time apps by creating efficient messaging systems between the server side and the client side using Socket.IO.

What You Will Learn

  • Build rich and interactive real-time dashboards using Socket.IO to pipe in data as it becomes available
  • Design chat and multiple-person interfaces that leverage Socket.IO for communication
  • Segment conversations to rooms and namespaces so that every socket doesn't have to receive every message
  • Secure your data by implementing various authentication techniques, locking down the HTTP referrer and using secure WebSockets
  • Load balance across multiple server-side nodes and keep your WebSockets in sync using Redis, RabbitMQ or Memcached
  • Stream binary data such as audio and video in real-time over a Socket.IO connection
  • Create real-time experiences outside of the browser by integrating Socket.IO with hybrid mobile applications

Who This Book Is For

If you have some knowledge of JavaScript and Node.js and want to create awe-inspiring application experiences using real time communication, then this book is for you. Developers with knowledge of other scripting languages should also be able to easily follow along.

Style and approach

This book is written in a cookbook-style format and provides practical, immediately usable task-based recipes that show you how to create the elements of a Socket.IO application.

Table of contents

  1. Socket.IO Cookbook
    1. Table of Contents
    2. Socket.IO Cookbook
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Sections
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      5. Conventions
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Wiring It Up
      1. Introduction
      2. Creating a Node HTTP server with Socket.IO
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      3. Creating an Express server with Socket.IO
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. See also
      4. Using Socket.IO as a cross-browser WebSocket
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      5. Debugging on the client
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      6. Debugging on the server
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
    9. 2. Creating Real-Time Dashboards
      1. Introduction
      2. Loading static data from the server
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      3. Creating a server-side clock
        1. How to do it…
        2. How it works…
      4. Loading data from MongoDB
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Real-time analytics
        1. How to do it…
        2. How it works…
        3. There's more…
      6. Handling connection timeouts
        1. Getting ready
        2. How to do it…
        3. How it works…
    10. 3. Having Two-Way Conversations
      1. Introduction
      2. Creating a simple chat room
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      3. Managing the socket life cycle
        1. How to do it…
        2. How it works…
      4. Emitting a private message to another socket
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Sending messages to all the sockets, except for the sender
        1. How to do it…
        2. How it works…
      6. Building a multiplayer tic-tac-toe game
        1. Getting ready
        2. How to do it…
        3. How it works…
    11. 4. Building a Room with a View
      1. Introduction
      2. Creating chat channels with namespaces
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Joining rooms
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Leaving rooms
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Listing rooms the socket is in
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      6. Creating private rooms
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Setting up a default room
        1. Getting ready
        2. How to do it…
        3. How it works…
    12. 5. Securing Your Data
      1. Introduction
      2. Implementing basic authentication
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Performing token-based authentication
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Handling server-side validation
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Locking down the HTTP referrer
        1. How to do it…
        2. How it works…
      6. Using secure WebSockets
        1. Getting ready
        2. How to do it…
        3. How it works…
    13. 6. Performing a Load Balancing Act
      1. Introduction
      2. Performing load balancing with the Nginx server
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Using the Node.js cluster
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Using Redis to pass events between nodes
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Using Memcached to manage multiple nodes
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Using RabbitMQ to message events across nodes
        1. Getting ready
        2. How to do it…
        3. How it works…
    14. 7. Streaming Binary Data
      1. Introduction
      2. Broadcasting an image to other sockets
        1. Getting ready…
        2. How to do it…
        3. How it works…
        4. There's more…
      3. Uploading an image to the filesystem
        1. Getting ready…
        2. How to do it…
        3. How it works…
      4. Uploading an image to Amazon S3
        1. Getting ready…
        2. How to do it…
        3. How it works…
      5. Streaming audio
        1. How to do it…
        2. How it works…
      6. Streaming live video
        1. How to do it…
        2. How it works…
    15. 8. Integrating with Mobile Applications
      1. Introduction
      2. Throwing an alert when the socket connects
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Pushing up data from the server
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Responding to tap events from the device
        1. How to do it…
        2. How it works…
      5. Doing server-side pagination
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Triggering hot deploys
        1. How to do it…
        2. How it works…
    16. Index

Product information

  • Title: Socket.IO Cookbook
  • Author(s): Tyson Cadenhead
  • Release date: October 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781785880865