Book Image

Websocket Essentials: Building apps with HTML5 websockets

By : Varun Chopra
Book Image

Websocket Essentials: Building apps with HTML5 websockets

By: Varun Chopra

Overview of this book

Table of Contents (13 chapters)
WebSocket Essentials – Building Apps with HTML5 WebSockets
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
6
Enhancing HTML5 Web Application Development Using Modern Tools
Index

How it works?


WebSockets communicates using the TCP layer. The connection is established over HTTP and is basically a handshake mechanism between the client and server. After the handshake, the connection is upgraded to TCP. Let's see how it works through this flow diagram:

The following steps will take you through the flow shown in the preceding diagram:

  1. The first step is the HTTP call that is initiated from the client side; the header of the HTTP call looks like this:

    GET /chat HTTP/1.1
    Host: server.example.com
    Upgrade: websocket
    Connection: Upgrade
    Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
    Sec-WebSocket-Protocol: chat, superchat
    Sec-WebSocket-Version: 13
    Origin: http://example.com
    
    • Here, Host is the name of the server that we are hitting.

    • Upgrade shows that it is an upgrade call for, in this case, WebSockets. Connection defines that it is an upgrade call.

    • Sec-Websocket-Key is a randomly generated key which is further used to authenticate the response. It is the authentication key of the...