WebSocket

Book description

Until recently, creating desktop-like applications in the browser meant using inefficient Ajax or Comet technologies to communicate with the server. With this practical guide, you’ll learn how to use WebSocket, a protocol that enables the client and server to communicate with each other on a single connection simultaneously. No more asynchronous communication or long polling!

For developers with a good grasp of JavaScript (and perhaps Node.js), author Andrew Lombardi provides useful hands-on examples throughout the book to help you get up to speed with the WebSocket API. You’ll also learn how to use WebSocket with Transport Layer Security (TLS).

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Who Should Read This Book
    2. Goals of This Book
    3. Navigating This Book
    4. Conventions Used in This Book
    5. Using Code Examples
    6. Safari® Books Online
    7. How to Contact Us
    8. Acknowledgments
  2. 1. Quick Start
    1. Getting Node and npm
      1. Installing on Windows
      2. Installing on OS X
      3. Installing on Linux
    2. Hello, World! Example
    3. Why WebSocket?
    4. Summary
  3. 2. WebSocket API
    1. Initializing
    2. Stock Example UI
    3. WebSocket Events
      1. Event: Open
      2. Event: Message
      3. Event: Error
      4. Event: PING/PONG
      5. Event: Close
    4. WebSocket Methods
      1. Method: Send
      2. Method: Close
    5. WebSocket Attributes
      1. Attribute: readyState
      2. Attribute: bufferedAmount
      3. Attribute: protocol
    6. Stock Example Server
    7. Testing for WebSocket Support
    8. Summary
  4. 3. Bidirectional Chat
    1. Long Polling
    2. Writing a Basic Chat Application
    3. WebSocket Client
    4. Client Identity
    5. Events and Notifications
    6. The Server
    7. The Client
    8. Summary
  5. 4. STOMP over WebSocket
    1. Implementing STOMP
      1. Getting Connected
      2. Connecting via the Server
    2. Setting Up RabbitMQ
    3. Connecting the Server to RabbitMQ
      1. The Stock Price Daemon
    4. Processing STOMP Requests
    5. Client
    6. Using RabbitMQ with Web-Stomp
      1. STOMP Client for Web and Node.js
      2. Installing the Web-Stomp Plug-in
      3. Echo Client for Web-Stomp
    7. Summary
  6. 5. WebSocket Compatibility
    1. SockJS
      1. SockJS Chat Server
      2. SockJS Chat Client
    2. Socket.IO
      1. Adobe Flash Socket
      2. Connecting
      3. Socket.IO Chat Server
      4. Socket.IO Chat Client
    3. Pusher.com
      1. Channels
      2. Events
      3. Pusher Chat Server
      4. Pusher Chat Client
      5. Don’t Forget: Pusher Is a Commercial Solution
    4. Reverse Proxy
    5. Summary
  7. 6. WebSocket Security
    1. TLS and WebSocket
      1. Generating a Self-Signed Certificate
      2. Installing on Windows
      3. Installing on OS X
      4. Installing on Linux
      5. Setting up WebSocket over TLS
      6. WebSocket Server over TLS Example
    2. Origin-Based Security Model
      1. Clickjacking
      2. X-Frame-Options for Framebusting
    3. Denial of Service
    4. Frame Masking
    5. Validating Clients
      1. Setting Up Dependencies and Inits
      2. Listening for Web Requests
      3. WebSocket Server
    6. Summary
  8. 7. Debugging and Tools
    1. The Handshake
      1. The Server
      2. The Client
      3. Download and Configure ZAP
    2. WebSocket Secure to the Rescue
    3. Validating the Handshake
    4. Inspecting Frames
      1. Masked Payloads
    5. Closing Connection
    6. Summary
  9. 8. WebSocket Protocol
    1. HTTP 0.9—The Web Is Born
    2. HTTP 1.0 and 1.1
    3. WebSocket Open Handshake
      1. Sec-WebSocket-Key and Sec-WebSocket-Accept
      2. WebSocket HTTP Headers
    4. WebSocket Frame
      1. Fin Bit
      2. Frame Opcodes
      3. Masking
      4. Length
      5. Fragmentation
    5. WebSocket Close Handshake
    6. WebSocket Subprotocols
    7. WebSocket Extensions
    8. Alternate Server Implementations
    9. Summary
  10. Index

Product information

  • Title: WebSocket
  • Author(s):
  • Release date: September 2015
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449369279