O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting Started with HTML5 WebSocket Programming

Book Description

Develop and deploy your first secure and scalable real-time web application

  • Start real-time communication in your web applications
  • Create a feature-rich WebSocket chat application
  • Learn the step-by-step configuration of the server and clients

In Detail

WebSockets are capable of bi-directional, full-duplex communication over a persistent TCP connection They provide many benefits compared to the alternatives (for example, long-polling or Comet), such as lower overhead, persistent connections, and low latency. In short, it is the most technically challenging HTML5 feature to implement, but for truly interactive websites, it's a technology worth learning.

Getting Started with HTML5 WebSocket Programming gives you the true power of bi-directional communication, implemented by using the brand new HTML5 WebSocket API. You’ll learn how to configure the server and clients, how to transmit different types of data and how to secure the whole system.

This book will introduce you to the WebSocket world. We start by introducing the WebSocket API, and continue with practical, real-world examples until we can determine how to build multi-functional web apps for any type of device.

You will learn how to configure a web client and a web server that will help you send messages to others using easy-to-use mechanisms. We will also find out how different data types, such as images and videos, can be transferred with little effort. We present additional fallback techniques and solutions for older browsers too. Finally, we will secure our clients from malicious attacks and other threats.

Table of Contents

  1. Getting Started with HTML5 WebSocket Programming
    1. Table of Contents
    2. Getting Started with HTML5 WebSocket Programming
    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. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. WebSocket – a Handshake!
      1. Life before WebSocket
        1. Polling
        2. Long polling
        3. Streaming
        4. Postback and AJAX
      2. Then came HTML5
      3. The WebSocket protocol
        1. The URL
        2. Browser support
        3. Who's using WebSockets
      4. Mobile?
      5. The future is now
      6. What are we going to make?
      7. Summary
    9. 2. The WebSocket API
      1. HTML5 basics
        1. Markup
        2. Styling
        3. Logic
      2. A chatting application
      3. API overview
        1. Browser support
        2. The WebSocket object
        3. Events
          1. onopen
          2. onmessage
          3. onclose
          4. onerror
        4. Actions
          1. send()
          2. close()
        5. Properties
        6. The complete example
          1. index.html
          2. chat.js
        7. What about the server?
      4. Summary
    10. 3. Configuring the Server
      1. Why do I need a WebSocket server?
      2. Setting up the server
        1. Selecting the technology that suits you
          1. C/C++
          2. Java
          3. .NET
          4. PHP
          5. Python
          6. Ruby
          7. JavaScript
        2. Setting up the development environment
      3. Connecting to the web server
        1. Creating the WebSocket server instance
        2. Open
        3. Close
        4. Message
        5. Send
      4. Other methods
      5. The complete source code
      6. Summary
    11. 4. Data Transfer – Sending, Receiving, and Decoding
      1. What kinds of data can WebSockets transfer?
        1. String
          1. JSON
          2. XML
        2. ArrayBuffer
        3. Blobs
          1. Video streaming
      2. Putting it all together
        1. Sending the nickname and message using JSON
        2. Sending images to the server
      3. Summary
    12. 5. Security
      1. WebSocket headers
      2. Common attacks
        1. Denial of Service
        2. Man-in-the-middle
        3. XSS
      3. WebSocket native defence mechanisms
        1. SSH/TLS
        2. Client-to-Server masking
      4. Security toolbox
        1. Fiddler
        2. Wireshark
        3. Browser developer tools
        4. ZAP
      5. Summary
    13. 6. Error Handling and Fallbacks
      1. Error handling
        1. Checking network availability
      2. Fallback solutions
        1. JavaScript polyfills
          1. Popular polyfills
        2. Browser plugins
      3. Summary
    14. 7. Going Mobile (and Tablet, Too)
      1. Why mobile matters
        1. Native mobile app versus mobile website
        2. Prerequisites
        3. Installing the SDK
        4. Testing our existing code in the mobile browser
      2. Going native
        1. Creating the project
        2. Creating the WebSocket iPhone app
      3. What about the iPad?
      4. Summary
    15. A. Appendix
      1. Resources
        1. Online sources
        2. Articles
      2. Source code
        1. System requirements
        2. Stay in touch
    16. Index