HyBi Working Group                                              I. Fette
Internet-Draft                                              Google, Inc.
Intended status: Standards Track                          April 22,                            June 7, 2011
Expires: October 24, December 9, 2011

                         The WebSocket protocol
                draft-ietf-hybi-thewebsocketprotocol-07
                draft-ietf-hybi-thewebsocketprotocol-08

Abstract

   The WebSocket protocol enables two-way communication between a user
   agent client
   running untrusted code running in a controlled environment to a
   remote host that has opted-in to communications from that code.  The
   security model used for this is the Origin-based security model
   commonly used by Web browsers.  The protocol consists of an initial opening
   handshake followed by basic message framing, layered over TCP.  (In
   theory, any transport protocol could be used so long as it provides
   for reliable transport, is byte clean, and supports relatively large
   message sizes.  However, for this document, we consider only TCP.)
   The goal of this technology is to provide a mechanism for browser-based browser-
   based applications that need two-way communication with servers that
   does not rely on opening multiple HTTP connections (e.g. using
   XMLHttpRequest or <iframe>s and long polling).

   Please send feedback to the hybi@ietf.org mailing list.

Status of this Memo

   This Internet-Draft is submitted in full conformance with the
   provisions of BCP 78 and BCP 79.

   Internet-Drafts are working documents of the Internet Engineering
   Task Force (IETF).  Note that other groups may also distribute
   working documents as Internet-Drafts.  The list of current Internet-
   Drafts is at http://datatracker.ietf.org/drafts/current/.

   Internet-Drafts are draft documents valid for a maximum of six months
   and may be updated, replaced, or obsoleted by other documents at any
   time.  It is inappropriate to use Internet-Drafts as reference
   material or to cite them other than as "work in progress."

   This Internet-Draft will expire on October 24, December 9, 2011.

Copyright Notice

   Copyright (c) 2011 IETF Trust and the persons identified as the
   document authors.  All rights reserved.

   This document is subject to BCP 78 and the IETF Trust's Legal
   Provisions Relating to IETF Documents
   (http://trustee.ietf.org/license-info) in effect on the date of
   publication of this document.  Please review these documents
   carefully, as they describe your rights and restrictions with respect
   to this document.  Code Components extracted from this document must
   include Simplified BSD License text as described in Section 4.e of
   the Trust Legal Provisions and are provided without warranty as
   described in the Simplified BSD License.

Table of Contents

   1.  Introduction . . . . . . . . . . . . . . . . . . . . . . . . .  4
     1.1.   Background  . . . . . . . . . . . . . . . . . . . . . . . .  4
     1.2.   Protocol overview Overview . . . . . . . . . . . . . . . . . . . .  4
     1.3.   Opening handshake Handshake . . . . . . . . . . . . . . . . . . . .  6
     1.4.   Closing handshake Handshake . . . . . . . . . . . . . . . . . . . .  8  9
     1.5.   Design philosophy Philosophy . . . . . . . . . . . . . . . . . . . .  9
     1.6.   Security model . Model  . . . . . . . . . . . . . . . . . . . . . 10
     1.7.   Relationship to TCP and HTTP  . . . . . . . . . . . . . . . 10 11
     1.8.   Establishing a connection Connection . . . . . . . . . . . . . . . . 11
     1.9.   Subprotocols using Using the WebSocket protocol . . . . . . . . 11
   2.  Conformance requirements Requirements . . . . . . . . . . . . . . . . . . . 13
     2.1.   Terminology . . . . . . . . . . . . . . . . . . . . . . . 13
   3.  WebSocket URIs . . . . . . . . . . . . . . . . . . . . . . . . 15
     3.1.  Parsing WebSocket URIs . . . . . . . . . . . . . . . . . . 15
     3.2.  Constructing WebSocket URIs  . . . . . . . . . . . . . . . 16
     3.3.  Valid WebSocket URIs . . . . . . . . . . . . . . . . . . . 16
   4.  Data Framing . . . . . . . . . . . . . . . . . . . . . . . . . 17 16
     4.1.   Overview  . . . . . . . . . . . . . . . . . . . . . . . . . 17 16
     4.2.   Base Framing Protocol . . . . . . . . . . . . . . . . . . 17 16
     4.3.   Client-to-Server Masking  . . . . . . . . . . . . . . . . . 20
     4.4.   Fragmentation . . . . . . . . . . . . . . . . . . . . . . 21
     4.5.   Control Frames  . . . . . . . . . . . . . . . . . . . . . . 23 22
       4.5.1.  Close  . . . . . . . . . . . . . . . . . . . . . . . . 23
       4.5.2.  Ping . . . . . . . . . . . . . . . . . . . . . . . . . 24 23
       4.5.3.  Pong . . . . . . . . . . . . . . . . . . . . . . . . . 24
     4.6.   Data Frames . . . . . . . . . . . . . . . . . . . . . . . 24
     4.7.   Examples  . . . . . . . . . . . . . . . . . . . . . . . . . 25
     4.8.   Extensibility . . . . . . . . . . . . . . . . . . . . . . 25
   5.  Opening Handshake  . . . . . . . . . . . . . . . . . . . . . . 27
     5.1.   Client Requirements . . . . . . . . . . . . . . . . . . . 27
     5.2.   Server-side requirements . Requirements  . . . . . . . . . . . . . . . . 31 32
       5.2.1.  Reading the client's opening handshake Client's Opening Handshake . . . . . . . . 32
       5.2.2.  Sending the server's opening handshake Server's Opening Handshake . . . . . . . . 32 33
   6.  Error Handling  Sending and Receiving Data . . . . . . . . . . . . . . . . . . 37
     6.1.   Sending Data  . . . . . . 36
     6.1.  Handling errors in UTF-8 from the server . . . . . . . . . 36 . . . . . . . 37
     6.2.  Handling errors in UTF-8 from the client   Receiving Data  . . . . . . . . . . 36 . . . . . . . . . . . 37
   7.  Closing the connection . . . . . . . . . . . . . . . . . . . . 37 39
     7.1.   Definitions . . . . . . . . . . . . . . . . . . . . . . . 37 39
       7.1.1.  Close the WebSocket Connection . . . . . . . . . . . . 37 39
       7.1.2.  Start the WebSocket Closing Handshake  . . . . . . . . 37 39
       7.1.3.  The WebSocket Closing Handshake is Started . . . . . . 39
       7.1.4.  The WebSocket Connection Is is Closed . . . . . . . . . . 37
       7.1.4. 40
       7.1.5.  The WebSocket Connection Close Code  . . . . . . . . . 40
       7.1.6.  The WebSocket Connection Close Reason  . . . . . . . . 40
       7.1.7.  Fail the WebSocket Connection  . . . . . . . . . . . . 37 41
     7.2.   Abnormal closures Closures . . . . . . . . . . . . . . . . . . . . 37 41
       7.2.1.  Client-initiated closure  Client-Initiated Closure . . . . . . . . . . . . . . . 38 41
       7.2.2.  Server-initiated closure . . . . . . . . . . . . . . . 38 42
     7.3.   Normal closure Closure of connections Connections . . . . . . . . . . . . . . 38 42
     7.4.   Status codes . Codes  . . . . . . . . . . . . . . . . . . . . . . 38 42
       7.4.1.  Defined Status Codes . . . . . . . . . . . . . . . . . 38 42
       7.4.2.  Reserved status code ranges Status Code Ranges  . . . . . . . . . . . . . 39 43
   8.  Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 45
     8.1.   Handling Errors in UTF-8 from the Server  . . . . . . . . 45
     8.2.   Handling Errors in UTF-8 from the Client  . . . . . . . . 45
   9.  Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . 41
     8.1. 46
     9.1.   Negotiating extensions . Extensions  . . . . . . . . . . . . . . . . . 41
     8.2. 46
     9.2.   Known extensions . Extensions  . . . . . . . . . . . . . . . . . . . . 42
       8.2.1. 47
       9.2.1.  Compression  . . . . . . . . . . . . . . . . . . . . . 42
   9. 47
   10. Security considerations Considerations  . . . . . . . . . . . . . . . . . . . 44
   10. 49
   11. IANA considerations Considerations  . . . . . . . . . . . . . . . . . . . . . 46
     10.1. 51
     11.1.  Registration of ws: scheme . . "ws:" Scheme  . . . . . . . . . . . . . . 46
     10.2. 51
     11.2.  Registration of wss: scheme  . "wss:" Scheme . . . . . . . . . . . . . . 47
     10.3. 52
     11.3.  Registration of the "WebSocket" HTTP Upgrade keyword . Keyword  . . 48
     10.4. 53
     11.4.  Sec-WebSocket-Key . . . . . . . . . . . . . . . . . . . . 48
     10.5. 53
     11.5.  Sec-WebSocket-Extensions  . . . . . . . . . . . . . . . . 54
     11.6.  WebSocket Extension Name Registry . 49
     10.6. Sec-WebSocket-Accept . . . . . . . . . . . 55
     11.7.  Sec-WebSocket-Accept  . . . . . . . . . . . . . 50
     10.7. Sec-WebSocket-Origin . . . . . 56
     11.8.  Sec-WebSocket-Origin  . . . . . . . . . . . . . . . . 50
     10.8. . . 56
     11.9.  Sec-WebSocket-Protocol  . . . . . . . . . . . . . . . . . 57
     11.10. WebSocket Subprotocol Name Registry . . 51
     10.9. . . . . . . . . . 57
     11.11. Sec-WebSocket-Version . . . . . . . . . . . . . . . . . . 51
   11. 58
     11.12. WebSocket Version Number Registry . . . . . . . . . . . . 59
     11.13. WebSocket Close Code Number Registry  . . . . . . . . . . 60
     11.14. WebSocket Opcode Registry . . . . . . . . . . . . . . . . 61
     11.15. WebSocket Framing Header Bits Registry  . . . . . . . . . 62
   12. Using the WebSocket protocol from other specifications Other Specifications . . . . 53
   12. 63
   13. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 54
   13. 64
   14. References . . . . . . . . . . . . . . . . . . . . . . . . . . 55
     13.1. 65
     14.1.  Normative References  . . . . . . . . . . . . . . . . . . . 55
     13.2. 65
     14.2.  Informative References  . . . . . . . . . . . . . . . . . . 56 66
   Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 57 68

1.  Introduction

1.1.  Background

   _This section is non-normative._

   Historically, creating an instant messenger chat client as a Web
   application has required an abuse of HTTP to poll the server for
   updates while sending upstream notifications as distinct HTTP
   calls.[RFC6202]

   This results in a variety of problems:

   o  The server is forced to use a number of different underlying TCP
      connections for each client: one for sending information to the
      client, and a new one for each incoming message.

   o  The wire protocol has a high overhead, with each client-to-server
      message having an HTTP header.

   o  The client-side script is forced to maintain a mapping from the
      outgoing connections to the incoming connection to track replies.

   A simpler solution would be to use a single TCP connection for
   traffic in both directions.  This is what the WebSocket protocol
   provides.  Combined with the WebSocket API, it provides an
   alternative to HTTP polling for two-way communication from a Web page
   to a remote server.  [WSAPI]

   The same technique can be used for a variety of Web applications:
   games, stock tickers, multiuser applications with simultaneous
   editing, user interfaces exposing server-side services in real time,
   etc.

1.2.  Protocol overview Overview

   _This section is non-normative._

   The protocol has two parts: a handshake, and then the data transfer.

   The handshake from the client looks as follows:

        GET /chat HTTP/1.1
        Host: server.example.com
        Upgrade: websocket
        Connection: Upgrade
        Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
        Sec-WebSocket-Origin: http://example.com
        Sec-WebSocket-Protocol: chat, superchat
        Sec-WebSocket-Version: 7 8

   The handshake from the server looks as follows:

        HTTP/1.1 101 Switching Protocols
        Upgrade: websocket
        Connection: Upgrade
        Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
        Sec-WebSocket-Protocol: chat

   The leading line from the client follows the Request-Line format.
   The leading line from the server follows the Status-Line format.  The
   Request-Line and Status-Line productions are defined in [RFC2616].

   After the leading line in both cases come an unordered set of header
   fields.  The meaning of these header fields is specified in Section 5
   of this document.  Additional header fields may also be present, such
   as cookies [I-D.ietf-httpstate-cookie] required to identify the user.
   The format and parsing of headers is as defined in [RFC2616].

   Once the client and server have both sent their handshakes, and if
   the handshake was successful, then the data transfer part starts.
   This is a two-way communication channel where each side can,
   independently from the other, send data at will.

   Clients and servers, after a successful handshake, transfer data back
   and forth in conceptual units referred to in this specification as
   "messages".  A message is a complete unit of data at an application
   level, with the expectation that many or most applications
   implementing this protocol (such as web user agents) provide APIs in
   terms of sending and receiving messages.  The websocket WebSocket message does
   not necessarily correspond to a particular network layer framing, as
   a fragmented message may be coalesced, or vice versa, e.g. by an
   intermediary.

   Data is sent on the wire in the form of frames that have an
   associated type.  A message is composed of one or more frames, all of
   which contain the same type of data.  Broadly speaking, there are
   types for textual data, which is interpreted as UTF-8 [RFC3629] text,
   binary data (whose interpretation is left up to the application), and
   control frames, which are not intended to carry data for the
   application, but instead for protocol-level signaling, such as to
   signal that the connection should be closed.  This version of the
   protocol defines six frame types and leaves ten reserved for future
   use.

   The WebSocket protocol uses this framing so that specifications that
   use the WebSocket protocol can expose such connections using an
   event-based mechanism instead of requiring users of those
   specifications to implement buffering and piecing together of
   messages manually.

1.3.  Opening handshake Handshake

   _This section is non-normative._

   The opening handshake is intended to be compatible with HTTP-based
   server-side software and intermediaries, so that a single port can be
   used by both HTTP clients talking to that server and WebSocket
   clients talking to that server.  To this end, the WebSocket client's
   handshake is an HTTP Upgrade request:

        GET /chat HTTP/1.1
        Host: server.example.com
        Upgrade: websocket
        Connection: Upgrade
        Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
        Sec-WebSocket-Origin: http://example.com
        Sec-WebSocket-Protocol: chat, superchat
        Sec-WebSocket-Version: 7 8

   Headers in the handshake are sent by the client in a random order;
   the order is not meaningful.

   The "Request-URI" of the GET method [RFC2616] is used to identify the
   endpoint of the WebSocket connection, both to allow multiple domains
   to be served from one IP address and to allow multiple WebSocket
   endpoints to be served by a single server.

   The client includes the hostname in the Host header of its handshake
   as per [RFC2616], so that both the client and the server can verify
   that they agree on which host is in use.

   Additional headers are used to select options in the WebSocket
   protocol.  Options available in this version are the subprotocol
   selector, |Sec-WebSocket-Protocol|, and |Cookie|, which can used for
   sending cookies to the server (e.g. as an authentication mechanism).

   The |Sec-WebSocket-Protocol| request-header field can be used to
   indicate what subprotocols (application-level protocols layered over
   the WebSocket protocol) are acceptable to the client.  The server
   selects one of the acceptable protocols and echoes that value in its
   handshake to indicate that it has selected that protocol.
        Sec-WebSocket-Protocol: chat

   The |Sec-WebSocket-Origin| header is used to protect against
   unauthorized cross-origin use of a WebSocket server by scripts using
   the |WebSocket| API in a Web browser.  The server is informed of the
   script origin generating the WebSocket connection request.  If the
   server does not wish to accept connections from this origin, it can
   choose to abort reject the connection. connection by sending an appropriate HTTP error
   code.  This header is sent by browser clients, for non-browser
   clients this header may be sent if it makes sense in the context of
   those clients.

   Finally,

   NOTE: It is worth noting that for the server has to prove to attack cases this header
   protects against, the client untrusted party is typically the author of a
   JavaScript application that it received is executing in the context of the
   client.  The client itself can contact the server and via the
   mechanism of the |Sec-WebSocket-Origin| header, determine whether to
   extend those communication privileges to the JavaScript application.
   A JavaScript application cannot set a header starting with "Sec-" via
   XHR.  The intent is not to prevent non-browsers from establishing
   connections, but rather to ensure that browsers under the control of
   potentially malicious JavaScript cannot fake a WebSocket handshake.

   Finally, the server has to prove to the client that it received the
   client's WebSocket handshake, so that the server doesn't accept
   connections that are not WebSocket connections.  This prevents an
   attacker from tricking a WebSocket server by sending it carefully-
   crafted packets using |XMLHttpRequest| or a |form| submission.

   To prove that the handshake was received, the server has to take two
   pieces of information and combine them to form a response.  The first
   piece of information comes from the |Sec-WebSocket-Key| header in the
   client handshake:

        Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==

   For this header, the server has to take the value (as present in the
   header, e.g. the base64-encoded [RFC4648] version minus leading and
   trailing whitespace), and concatenate this with the GUID "258EAFA5-
   E914-47DA-95CA-C5AB0DC85B11" in string form, which is unlikely to be
   used by network endpoints that do not understand the WebSocket
   protocol.  A SHA-1 hash, hash (160 bits), base64-encoded, of this
   concatenation is then returned in the server's handshake

   [FIPS.180-2.2002].

   Concretely, if as in the example above, header |Sec-WebSocket-Key|
   had the value "dGhlIHNhbXBsZSBub25jZQ==", the server would
   concatenate the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" to form
   the string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
   C5AB0DC85B11".  The server would then take the SHA-1 hash of this,
   giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90 0xf6
   0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea.  This value is
   then base64-encoded, to give the value "s3pPLMBiTxaQ9kYGzzhZRbK+
   xOo=".  This value would then be echoed in the header |Sec-WebSocket-
   Accept|.

   The handshake from the server is much simpler than the client
   handshake.  The first line is an HTTP Status-Line, with the status
   code 101:

        HTTP/1.1 101 Switching Protocols

   Any status code other than 101 indicates that the WebSocket handshake
   has not completed, and that the semantics of HTTP still apply.  The
   headers follow the status code.

   The |Connection| and |Upgrade| headers complete the HTTP Upgrade.
   The |Sec-WebSocket-Accept| header indicates whether the server is
   willing to accept the connection.  If present, this header must
   include a hash of the client's nonce sent in |Sec-WebSocket-Key|
   along with a predefined GUID.  Any other value must not be
   interpreted as an acceptance of the connection by the server.

        HTTP/1.1 101 Switching Protocols
        Upgrade: websocket
        Connection: Upgrade
        Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

   These fields are checked by the Web browser when it is acting as a
   |WebSocket| client for scripted pages.  If the |Sec-WebSocket-Accept|
   value does not match the expected value, or if the header is missing,
   or if the HTTP status code is not 101, the connection will not be
   established and WebSockets WebSocket frames will not be sent.

   Option fields can also be included.  In this version of the protocol,
   the main option field is |Sec-WebSocket-Protocol|, which indicates
   the subprotocol that the server has selected.  Web browsers verify
   that the server included one of the values as was specified in the
   WebSocket client' client's handshake.  A server that speaks multiple
   subprotocols has to make sure it selects one based on the client's
   handshake and specifies it in its handshake.

        Sec-WebSocket-Protocol: chat

   The server can also set cookie-related option fields to _set_
   cookies, as in HTTP.

1.4.  Closing handshake Handshake

   _This section is non-normative._

   The closing handshake is far simpler than the opening handshake.

   Either peer can send a control frame with data containing a specified
   control sequence to begin the closing handshake (detailed in
   Section 4.5.1).  Upon receiving such a frame, the other peer sends a
   close frame in response, if it hasn't already sent one.  Upon
   receiving _that_ control frame, the first peer then closes the
   connection, safe in the knowledge that no further data is
   forthcoming.

   After sending a control frame indicating the connection should be
   closed, a peer does not send any further data; after receiving a
   control frame indicating the connection should be closed, a peer
   discards any further data received.

   It is safe for both peers to initiate this handshake simultaneously.

   The closing handshake is intended to replace complement the TCP closing
   handshake (FIN/ACK), on the basis that the TCP closing handshake is
   not always reliable end-to-end, especially in the presence of man-in-
   the-middle proxies and other intermediaries.

   By sending a close frame and waiting for a close frame in response,
   certain cases are avoided where data may be unnecessarily lost.  For
   instance, on some platforms, if a socket is closed with data in the
   receive queue, a RST packet is sent, which will then cause recv() to
   fail for the party that received the RST, even if there was data
   waiting to be read.

1.5.  Design philosophy Philosophy

   _This section is non-normative._

   The WebSocket protocol is designed on the principle that there should
   be minimal framing (the only framing that exists is to make the
   protocol frame-based instead of stream-based, and to support a
   distinction between Unicode text and binary frames).  It is expected
   that metadata would be layered on top of WebSocket by the application
   layer, in the same way that metadata is layered on top of TCP by the
   application layer (HTTP).

   Conceptually, WebSocket is really just a layer on top of TCP that
   adds a Web "origin"-based security model for browsers; adds an
   addressing and protocol naming mechanism to support multiple services
   on one port and multiple host names on one IP address; layers a
   framing mechanism on top of TCP to get back to the IP packet
   mechanism that TCP is built on, but without length limits; and re-
   implements the
   includes an additional closing handshake in-band. in-band that is designed to
   work in the presence of proxies and other intermediaries.  Other than
   that, it adds nothing.  Basically it is intended to be as close to
   just exposing raw TCP to script as possible given the constraints of
   the Web. It's also designed in such a way that its servers can share
   a port with HTTP servers, by having its handshake be a valid HTTP
   Upgrade request mechanism also.

   The protocol is intended to be extensible; future versions will
   likely introduce additional concepts such as multiplexing.

1.6.  Security model Model

   _This section is non-normative._

   The WebSocket protocol uses the origin model used by Web browsers to
   restrict which Web pages can contact a WebSocket server when the
   WebSocket protocol is used from a Web page.  Naturally, when the
   WebSocket protocol is used by a dedicated client directly (i.e. not
   from a Web page through a Web browser), the origin model is not
   useful, as the client can provide any arbitrary origin string.

   This protocol is intended to fail to establish a connection with
   servers of pre-existing protocols like SMTP [RFC5321] and HTTP, while
   allowing HTTP servers to opt-in to supporting this protocol if
   desired.  This is achieved by having a strict and elaborate
   handshake, and by limiting the data that can be inserted into the
   connection before the handshake is finished (thus limiting how much
   the server can be influenced).

   It is similarly intended to fail to establish a connection when data
   from other protocols, especially HTTP, is sent to a WebSocket server,
   for example as might happen if an HTML |form| were submitted to a
   WebSocket server.  This is primarily achieved by requiring that the
   server prove that it read the handshake, which it can only do if the
   handshake contains the appropriate parts which themselves can only be
   sent by a WebSocket handshake.  In particular, at the time of writing
   of this specification, fields starting with |Sec-| cannot be set by
   an attacker from a Web browser using only HTML and JavaScript APIs
   such as |XMLHttpRequest|.

1.7.  Relationship to TCP and HTTP

   _This section is non-normative._

   The WebSocket protocol is an independent TCP-based protocol.  Its
   only relationship to HTTP is that its handshake is interpreted by
   HTTP servers as an Upgrade request.

   By default the WebSocket protocol uses port 80 for regular WebSocket
   connections and port 443 for WebSocket connections tunneled over TLS
   [RFC2818].

1.8.  Establishing a connection Connection

   _This section is non-normative._

   When a connection is to be made to a port that is shared by an HTTP
   server (a situation that is quite likely to occur with traffic to
   ports 80 and 443), the connection will appear to the HTTP server to
   be a regular GET request with an Upgrade offer.  In relatively simple
   setups with just one IP address and a single server for all traffic
   to a single hostname, this might allow a practical way for systems
   based on the WebSocket protocol to be deployed.  In more elaborate
   setups (e.g. with load balancers and multiple servers), a dedicated
   set of hosts for WebSocket connections separate from the HTTP servers
   is probably easier to manage.  At the time of writing of this
   specification, it should be noted that connections on port 80 and 443
   have significantly different success rates, with connections on port
   443 being significantly more likely to succeed, though this may
   change with time.

1.9.  Subprotocols using Using the WebSocket protocol

   _This section is non-normative._

   The client can request that the server use a specific subprotocol by
   including the |Sec-WebSocket-Protocol| field in its handshake.  If it
   is specified, the server needs to include the same field and one of
   the selected subprotocol values in its response for the connection to
   be established.

   These subprotocol names do not need to should be registered, but if a
   subprotocol registered as per Section 11.10.
   To avoid potential collisions, it is intended recommended to be implemented by multiple independent
   WebSocket servers, potential clashes with the names of subprotocols
   defined independently can be avoided by using use names that
   contain the domain name of the subprotocol's originator.  For
   example, if Example Corporation were to create a Chat subprotocol to
   be implemented by many servers around the Web, they could name it
   "chat.example.com".  If the Example Organization called their
   competing subprotocol "example.org's chat protocol", then the two
   subprotocols could be implemented by servers simultaneously, with the
   server dynamically selecting which subprotocol to use based on the
   value sent by the client.

   Subprotocols can be versioned in backwards-incompatible ways by
   changing the subprotocol name, e.g. going from "bookings.example.net"
   to "v2.bookings.example.net".  These subprotocols would be considered
   completely separate by WebSocket clients.  Backwards-compatible
   versioning can be implemented by reusing the same subprotocol string
   but carefully designing the actual subprotocol to support this kind
   of extensibility.

2.  Conformance requirements Requirements

   All diagrams, examples, and notes in this specification are non-
   normative, as are all sections explicitly marked non-normative.
   Everything else in this specification is normative.

   The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT",
   "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this
   document are to be interpreted as described in RFC2119.  [RFC2119]

   Requirements phrased in the imperative as part of algorithms (such as
   "strip any leading space characters" or "return false and abort these
   steps") are to be interpreted with the meaning of the key word
   ("must", "should", "may", etc) used in introducing the algorithm.

   Conformance requirements phrased as algorithms or specific steps MAY
   be implemented in any manner, so long as the end result is
   equivalent.  (In particular, the algorithms defined in this
   specification are intended to be easy to follow, and not intended to
   be performant.)

   Implementations MAY impose implementation-specific limits on
   otherwise unconstrained inputs, e.g. to prevent denial of service
   attacks, to guard against running out of memory, or to work around
   platform-specific limitations.

   The conformance classes defined by this specification are user agents clients and
   servers.

2.1.  Terminology

   *ASCII*

   _ASCII_ shall mean the character-encoding scheme defined in
   [ANSI.X3-4.1986].

   *Converting

   This document makes reference to UTF-8 values and uses UTF-8
   notational formats as defined in STD 63 [RFC3629].

   Key Terms such as named algorithms or definitions are indicated like
   _this_.

   Names of headers or variables are indicated like |this|.

   Variable values are indicated like /this/.

   _Converting a string to ASCII lowercase* lowercase_ means replacing all
   characters in the range U+0041 to U+005A (i.e.  LATIN CAPITAL LETTER
   A to LATIN CAPITAL LETTER Z) with the corresponding characters in the
   range U+0061 to U+007A (i.e.  LATIN SMALL LETTER A to LATIN SMALL
   LETTER Z).

   Comparing two strings in an *ASCII case-insensitive* _ASCII case-insensitive_ manner means
   comparing them exactly, code point for code point, except that the
   characters in the range U+0041 to U+005A (i.e.  LATIN CAPITAL LETTER
   A to LATIN CAPITAL LETTER Z) and the corresponding characters in the
   range U+0061 to U+007A (i.e.  LATIN SMALL LETTER A to LATIN SMALL
   LETTER Z) are considered to also match.

   The term "URI" is used in this document as defined in [RFC3986].

   When an implementation is required to _send_ data as part of the
   WebSocket protocol, the implementation MAY delay the actual
   transmission arbitrarily, e.g. buffering data so as to send fewer IP
   packets.

3.  WebSocket URIs

3.1.  Parsing WebSocket URIs

   The steps to *parse a WebSocket URI's components* from a string /uri/
   are as follows.  These steps return either a /host/, a /port/, a
   /resource name/, and a /secure/ flag, or they fail.

   1.   If the /uri/ string is not an absolute URI, then fail this
        algorithm.  [RFC3986]

   2.   Resolve the /uri/ string

   This specification defines two URI schemes, using the resolve a Web address
        algorithm ABNF syntax
   defined in RFC 5234 [RFC5234], and terminology and ABNF productions
   defined by the Web addresses specification, with the URI character encoding set to UTF-8.  [RFC3629] [RFC3986]
        [RFC3987]

        NOTE: It doesn't matter what it specification RFC 3986 [RFC3986].

          ws-URI = "ws:" "//" host [ ":" port ] path [ "?" query ]
          wss-URI = "ws:" "//" host [ ":" port ] path [ "?" query ]

          host = <host, defined in [RFC3986], Section 3.2.2>
          port = <host, defined in [RFC3986], Section 3.2.3>
          path = <path-abempty, defined in [RFC3986], Section 3.3>
          query = <query, defined in [RFC3986], Section 3.4>

   The port component is resolved relative to, since
        we already know it OPTIONAL; the default for "ws" is an absolute port 80,
   while the default for "wss" is port 443.

   The URI at this point.

   3.   If /uri/ does not have a <scheme> component whose value, when
        converted to ASCII lowercase, is either "ws" or "wss", then fail
        this algorithm.

   4.   If /uri/ has a <fragment> component, then fail this algorithm.

   5.   If called "secure" if the <scheme> scheme component of /uri/ is "ws", set /secure/ to
        false; otherwise, matches "wss"
   case-insensitively.

   The "resource-name" can be constructed by concatenating

   "/" if the <scheme> path component is "wss", set
        /secure/ to true; if neither of empty
   the above apply, fail this
        algorithm.

   6.   Let /host/ be path component
   "?" if the value of query component is non-empty
   the <host> query component

   Fragment identifiers are meaningless in the context of /uri/,
        converted to ASCII lowercase.

   7.   If /uri/ has a <port> component, then let /port/ be that
        component's value; otherwise, there is no explicit /port/.

   8.   If there is no explicit /port/, then: if /secure/ is false, let
        /port/ be 80, otherwise let /port/ WebSocket
   URIs, and MUST NOT be 443.

   9.   Let /resource name/ used on these URIs.  The character "#" in URIs
   MUST be the value escaped as %23 if used as part of the <path> component (which
        might be empty) of /uri/.

   10.  If /resource name/ query component.

4.  Data Framing

4.1.  Overview

   In the WebSocket protocol, data is transmitted using a sequence of
   frames.  Frames sent from the empty string, set it client to a single
        character U+002F SOLIDUS (/).

   11.  If /uri/ has a <query> component, then append a single U+003F
        QUESTION MARK character (?) the server are masked to /resource name/, followed by
   avoid confusing network intermediaries, such as intercepting proxies.
   Frames sent from the
        value of server to the <query> component.

   12.  Return /host/, /port/, /resource name/, and /secure/.

3.2.  Constructing WebSocket URIs client are not masked.

   The steps to *construct a WebSocket URI* from a /host/, base framing protocol defines a /port/, frame type with an opcode, a
   /resource name/,
   payload length, and a /secure/ flag, are as follows:

   1.  Let /uri/ be the empty string.

   2.  If the /secure/ flag is false, then append designated locations for extension and
   application data, which together define the string "ws://" to
       /uri/.  Otherwise, append _payload_ data.  Certain
   bits and opcodes are reserved for future expansion of the string "wss://" to /uri/.

   3.  Append /host/ to /uri/.

   4.  If protocol.

   A data frame MAY be transmitted by either the /secure/ flag is false and port is not 80, client or if the
       /secure/ flag is true server at
   any time after opening handshake completion and port is not 443, then append before that endpoint
   has sent a close frame (Section 4.5.1).

4.2.  Base Framing Protocol

   This wire format for the string
       ":" followed data transfer part is described by /port/ to /uri/.

   5.  Append /resource name/ to /uri/.

   6.  Return /uri/.

3.3.  Valid WebSocket URIs

   For a WebSocket URI to be considered valid, the following conditions
   MUST hold.

   o  The /host/ MUST be ASCII-only (i.e. it MUST have been punycode-
      encoded [RFC3492] already if necessary, and MUST NOT contain any
      characters above U+007E).

   o  The /resource name/ string MUST be a non-empty string ABNF
   [RFC5234] given in detail in this section.  A high level overview of
      characters
   the framing is given in the range U+0021 to U+007E and MUST start with a
      U+002F SOLIDUS character (/).

   Any WebSocket URIs following figure.

      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-------+-+-------------+-------------------------------+
     |F|R|R|R| opcode|M| Payload len |    Extended payload length    |
     |I|S|S|S|  (4)  |A|     (7)     |             (16/63)           |
     |N|V|V|V|       |S|             |   (if payload len==126/127)   |
     | |1|2|3|       |K|             |                               |
     +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
     |     Extended payload length continued, if payload len == 127  |
     + - - - - - - - - - - - - - - - +-------------------------------+
     |                               |Masking-key, if MASK set to 1  |
     +-------------------------------+-------------------------------+
     | Masking-key (continued)       |          Payload Data         |
     +-------------------------------- - - - - - - - - - - - - - - - +
     :                     Payload Data continued ...                :
     + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
     |                     Payload Data continued ...                |
     +---------------------------------------------------------------+

   FIN:  1 bit

      Indicates that this is the final fragment in a message.  The first
      fragment MAY also be the final fragment.

   RSV1, RSV2, RSV3:  1 bit each

      MUST be 0 unless an extension is negotiated which defines meanings
      for non-zero values.  If a nonzero value is received and none of
      the negotiated extensions defines the meaning of such a nonzero
      value, the receiving endpoint MUST ignore that value.

   Opcode:  4 bits

      Defines the interpretation of the payload data.  If an unknown
      opcode is received, the receiving endpoint MUST ignore that frame.
      The following values are defined.

      *  %x0 denotes a continuation frame

      *  %x1 denotes a text frame

      *  %x2 denotes a binary frame

      *  %x3-7 are reserved for further non-control frames

      *  %x8 denotes a connection close

      *  %x9 denotes a ping

      *  %xA denotes a pong

      *  %xB-F are reserved for further control frames

   Mask:  1 bit

      Defines whether the payload data is masked.  If set to 1, a
      masking key is present in masking-key, and this is used to unmask
      the payload data as per Section 4.3.  All frames sent from client
      to server have this bit set to 1.

   Payload length:  7 bits, 7+16 bits, or 7+64 bits

      The length of the payload data, in bytes: if 0-125, that is the
      payload length.  If 126, the following 2 bytes interpreted as a 16
      bit unsigned integer are the payload length.  If 127, the
      following 8 bytes interpreted as a 64-bit unsigned integer (the
      most significant bit MUST be 0) are the payload length.  Multibyte
      length quantities are expressed in network byte order.  The
      payload length is the length of the extension data + the length of
      the application data.  The length of the extension data may be
      zero, in which case the payload length is the length of the
      application data.

   Masking-key:  0 or 4 bytes

      All frames sent from the client to the server are masked by a 32-
      bit value that is contained within the frame.  This field is
      present if the mask bit is set to 1, and is absent if the mask bit
      is set to 0.  See Section 4.3 for further information on client-
      to-server masking.

   Payload data:  (x+y) bytes

      The payload data is defined as extension data concatenated with
      application data.

   Extension data:  x bytes

      The extension data is 0 bytes unless an extension has been
      negotiated.  Any extension MUST specify the length of the
      extension data, or how that length may be calculated, and how the
      extension use MUST be negotiated during the opening handshake.  If
      present, the extension data is included in the total payload
      length.

   Application data:  y bytes

      Arbitrary application data, taking up the remainder of the frame
      after any extension data.  The length of the application data is
      equal to the payload length minus the length of the extension
      data.

   The base framing protocol is formally defined by the following ABNF
   [RFC5234]:

   ws-frame                = frame-fin
                             frame-rsv1
                             frame-rsv2
                             frame-rsv3
                             frame-opcode
                             frame-masked
                             frame-payload-length
                             [ frame-masking-key ]
                             frame-payload-data

   frame-fin               = %x0 ; more frames of this message follow
                           / %x1 ; final frame of this message

   frame-rsv1              = %x0 ; 1 bit, MUST be 0

   frame-rsv2              = %x0 ; 1 bit, MUST be 0

   frame-rsv3              = %x0 ; 1 bit, MUST be 0

   frame-opcode            = %x0 ; continuation frame
                           / %x1 ; text frame
                           / %x2 ; binary frame
                           / %x3-7 ; reserved for further non-control frames
                           / %x8 ; connection close
                           / %x9 ; ping
                           / %xA ; pong
                           / %xB-F ; reserved for further control frames

   frame-masked            = %x0 ; frame is not masked, no frame-masking-key
                           / %x1 ; frame is masked, frame-masking-key present

   frame-payload-length    = %x00-7D
                           / %x7E frame-payload-length-16
                           / %x7F frame-payload-length-63

   frame-payload-length-16 = %x0000-FFFF

   frame-payload-length-63 = %x0000000000000000-7FFFFFFFFFFFFFFF

   frame-masking-key       = 4( %0x00-FF ) ; present only if frame-masked is 1

   frame-payload-data      = (frame-masked-extension-data
                              frame-masked-application-data)   ; frame-masked 1
                           / (frame-unmasked-extension-data
                              frame-unmasked-application-data) ; frame-masked 0

   frame-masked-extension-data     = *( %x00-FF ) ; to be defined later

   frame-masked-application-data   = *( %x00-FF )

   frame-unmasked-extension-data   = *( %x00-FF ) ; to be defined later

   frame-unmasked-application-data = *( %x00-FF )

4.3.  Client-to-Server Masking

   The client MUST mask all frames sent to the server.  A server MUST
   close the connection upon receiving a frame with the MASK bit set to
   0.  In this case, a server MAY send a close frame with a status code
   of 1002 (protocol error) as defined in Section 7.4.1.

   A masked frame MUST have the field frame-masked set to 1, as defined
   in Section 4.2.

   The masking key is contained completely within the frame, as defined
   in Section 4.2 as frame-masking-key.  It is used to mask the payload
   data defined in the same section as frame-payload-data, which
   includes extension and application data.

   The masking key is a 32-bit value chosen at random by the client.
   The masking key MUST be derived from a strong source of entropy, and
   the masking key for a given frame MUST NOT make it simple for a
   server to predict the masking key for a subsequent frame.  RFC 4086
   [RFC4086] discusses what entails a suitable source of entropy for
   security-sensitive applications.

   The masking does not meeting affect the above criteria length of the payload data.  To
   convert masked data into unmasked data, or vice versa, the following
   algorithm is applied.  The same algorithm applies regardless of the
   direction of the translation - e.g. the same steps are considered
   invalid.  A applied to
   mask the data as to unmask the data.

   Octet i of the transformed data ("transformed-octet-i") is the XOR of
   octet i of the original data ("original-octet-i") with octet i modulo
   4 of the masking key ("masking-key-octet-j"):

     j                   = i MOD 4
     transformed-octet-i = original-octet-i XOR masking-key-octet-j

   When preparing a masked frame, the client MUST pick a fresh masking
   key uniformly at random from the set of allowed 32-bit values.  The
   unpredictability of the masking key is essential to prevent the
   author of malicious applications from selecting the bytes that appear
   on the wire.

   The payload length, indicated in the framing as frame-payload-length,
   does NOT attempt include the length of the masking key.  It is the length of
   the payload data, e.g. the number of bytes following the masking key.

4.4.  Fragmentation

   The primary purpose of fragmentation is to make allow sending a connection message
   that is of unknown size when the message is started without having to
   buffer that message.  If messages couldn't be fragmented, then an
   invalid WebSocket URI.  A client SHOULD attempt
   endpoint would have to parse a URI
   obtained from any external source (such as buffer the entire message so its length could
   be counted before first byte is sent.  With fragmentation, a web site server
   or intermediary may choose a user)
   using reasonable size buffer, and when the steps specified in Section 3.1 to obtain
   buffer is full write a valid WebSocket
   URI, but MUST NOT attempt fragment to connect with such an unparsed URI, and
   instead only use the parsed version and only if that version network.

   A secondary use-case for fragmentation is
   considered valid by the criteria above.

4.  Data Framing

4.1.  Overview

   In the WebSocket protocol, data for multiplexing, where it
   is transmitted using not desirable for a sequence of
   frames.  Frames sent from the client large message on one logical channel to
   monopolize the server are masked output channel, so the MUX needs to
   avoid confusing network intermediaries, such as intercepting proxies.
   Frames sent from be free to split
   the server message into smaller fragments to better share the client are not masked. output
   channel.

   The base framing protocol defines following rules apply to fragmentation:

   o  An unfragmented message consists of a single frame type with the FIN
      bit set and an opcode, opcode other than 0.

   o  A fragmented message consists of a
   payload length, single frame with the FIN bit
      clear and designated locations for extension an opcode other than 0, followed by zero or more frames
      with the FIN bit clear and
   application data, which together define the _payload_ data.  Certain
   bits opcode set to 0, and opcodes are reserved for future expansion terminated by
      a single frame with the FIN bit set and an opcode of 0.  A
      fragmented message is conceptually equivalent to a single larger
      message whose payload is equal to the protocol.
   As such, concatenation of the
      payloads of the fragments in order, however in the absence presence of
      extensions negotiated during this may not hold true as the opening
   handshake (Section 5), all reserved bits MUST be 0 and reserved
   opcode values MUST NOT be used.

   A extension defines the
      interpretation of the extension data frame MAY present.  For instance,
      extension data may only be transmitted by either present at the client or beginning of the server at
   any time after handshake completion first
      fragment and before apply to subsequent fragments, or there may be
      extension data present in each of the fragments that endpoint has sent applies only
      to that particular fragment.  Setting aside the issue of
      extensions, the following example demonstrates how fragmentation
      works.

   o  EXAMPLE: For a close text message (Section 4.5.1).

4.2.  Base Framing Protocol

   This wire format for the data transfer part is described by sent as three fragments, the ABNF
   [RFC5234] given in detail in this section.  A high level overview first
      fragment would have an opcode of 0x1 and a FIN bit clear, the framing is given in
      second fragment would have an opcode of 0x0 and a FIN bit clear,
      and the following figure.

      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-------+-+-------------+-------------------------------+
     |F|R|R|R| opcode|M| Payload len |    Extended payload length    |
     |I|S|S|S|  (4)  |A|     (7)     |             (16/63)           |
     |N|V|V|V|       |S|             |   (if payload len==126/127)   |
     | |1|2|3|       |K|             |                               |
     +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
     |     Extended payload length continued, if payload len == 127  |
     + - - - - - - - - - - - - - - - +-------------------------------+
     |                               |Masking-key, if MASK set to 1  |
     +-------------------------------+-------------------------------+
     | Masking-key (continued)       |          Payload Data         |
     +-------------------------------- - - - - - - - - - - - - - - - +
     :                     Payload Data continued ...                :
     + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
     |                     Payload Data continued ...                |
     +---------------------------------------------------------------+

   FIN:  1 third fragment would have an opcode of 0x0 and a FIN bit

      Indicates
      that this is set.

   o  Control frames MAY be injected in the final fragment middle of a fragmented
      message.  Control frames themselves MUST NOT be fragmented.

   o  Message fragments MUST be delivered to the recipient in the order
      sent by the sender.

   o  An endpoint MUST be capable of handling control frames in the
      middle of a fragmented message.  The first
      fragment MAY also

   o  _Note: if control frames could not be interjected, the final fragment.

   RSV1, RSV2, RSV3:  1 bit each

      Must latency of
      a ping, for example, would be 0 unless an extension is negotiated which defines meanings very long if behind a large message.
      Hence, the requirement of handling control frames in the middle of
      a fragmented message._

   o  A sender MAY create fragments of any size for non-zero values

   Opcode:  4 bits

      Defines non-control
      messages.

   o  Clients and servers MUST support receiving both fragmented and
      unfragmented messages.

   o  As control frames cannot be fragmented, an intermediary MUST NOT
      attempt to change the interpretation fragmentation of a control frame.

   o  An intermediary MUST NOT change the payload data

   Mask:  1 fragmentation of a message if
      any reserved bit

      Defines whether values are used and the payload data meaning of these values
      is masked.  If set not known to 1, a
      masking key is present the intermediary.

   o  An intermediary MUST NOT change the fragmentation of any message
      in Masking-key, and this is used to unmask the payload data as per Section 4.3.  All frames sent from client
      to server have this bit set to 1.

   Payload length:  7 bits, 7+16 bits, or 7+64 bits

      The length context of a connection where extensions have been
      negotiated and the payload: if 0-125, that intermediary is not aware of the payload length.
      If 126, semantics of
      the following 2 bytes interpreted as negotiated extensions.

   o  As a 16 bit unsigned
      integer consequence of these rules, all fragments of a message are of
      the payload length.  If 127, the following 8 bytes
      interpreted same type, as a 64-bit unsigned integer (the most significant bit
      MUST set by the first fragment's opcode.  Since
      Control frames cannot be 0) are fragmented, the payload length.  Multibyte length quantities
      are expressed type for all fragments in network byte order.  The payload length is the
      length
      a message MUST be either text or binary, or one of the Extension data + reserved
      opcodes.

4.5.  Control Frames

   Control frames are identified by opcodes where the length most significant
   bit of the Application data.
      The length of opcode is 1.  Currently defined opcodes for control frames
   include 0x8 (Close), 0x9 (Ping), and 0xA (Pong).  Opcodes 0xB-0xF are
   reserved for further control frames yet to be defined.

   Control frames are used to communicate state about the Extension data may WebSocket.
   Control frames can be zero, interjected in which case the
      Payload length is the middle of a fragmented
   message.

   All control frames MUST have a payload length of the Application data. 125 bytes or less
   and MUST NOT be fragmented.

4.5.1.  Close

   The length Close frame contains an opcode of this field is always at least 7 bits.  If the value 0x8.

   The Close frame MAY contain a body (the "application data" portion of
   the
      first 7 bits is 0-125, frame) that indicates a reason for closing, such as an endpoint
   shutting down, an endpoint having received a frame too large, or an
   endpoint having received a frame that does not conform to the length of this field is 7 bits.  If format
   expected by the
      value is 126, there exist 16 additional bits with a 16-bit length. other endpoint.  If the value is 127, there exist 64 additional bits with is a 63-bit
      length (the most significant bit MUST be 0).

   Masking-key:  0 or 4 bytes

      All frames sent from body, the client to first two
   bytes of the server are masked by body MUST be a 32-
      bit 2-byte unsigned integer (in network byte
   order) representing a status code with value that is contained within the frame.  This field is
      present if /code/ defined in
   Section 7.4.  Following the Mask bit is set to 1, and is absent if 2-byte integer the Mask bit
      is set to 0.  See Section 4.3 for further information on client-
      to-server masking.

   Payload data:  n bytes

      The payload body MAY contain UTF-8
   encoded data with value /reason/, the interpretation of which is not
   defined as Extension Data concatenated with
      Application Data.

   Extension data:  n bytes

      The extension by this specification.  This data is 0 bytes unless an extension has been
      negotiated.  Any extension MUST specify the length of the
      extension data, or how that length not necessarily human
   readable, but may be calculated, and how useful for debugging or passing information
   relevant to the
      extension use MUST be negotiated during script that opened the handshake. connection.

   The application MUST NOT send any more data frames after sending a
   close frame.

   If
      present, an endpoint receives a Close frame and that endpoint did not
   previously send a Close frame, the extension data endpoint MUST send a Close frame
   in response.  It SHOULD do so as soon as is practical.  An endpoint
   MAY delay sending a close frame until its current message is included in the total payload
      length.

   Application data:  n bytes

      Arbitrary application data, taking up sent
   (for instance, if the remainder majority of a fragmented message is already
   sent, an endpoint MAY send the remaining fragments before sending a
   Close frame).  However, there is no guarantee that the endpoint which
   has already sent a Close frame
      after any extension will continue to process data.

   After both sending and receiving a close message, an endpoint
   considers the WebSocket connection closed, and MUST close the
   underlying TCP connection.  The length of server MUST close the Application data is
      equal to underlying TCP
   connection immediately; the payload length minus client SHOULD wait for the length of server to
   close the Extension
      data.

   The base framing protocol is formally defined by connection but MAY close the following ABNF
   [RFC5234]:

   ws-frame                = frame-fin
                             frame-rsv1
                             frame-rsv2
                             frame-rsv3
                             frame-opcode
                             frame-masked
                             frame-payload-length
                             [ frame-masking-key ]
                             frame-payload-data

   frame-fin               = %x0 ; more frames of this connection at any time after
   sending and receiving a close message, e.g. if it has not received a
   TCP close from the server in a reasonable time period.

   If a client and server both send a Close message follow
                           / %x1 ; final frame of at the same time,
   both endpoints will have sent and received a Close message

   frame-rsv1              = %x0 ; 1 bit, MUST be 0

   frame-rsv2              = %x0 ; 1 bit, MUST be 0

   frame-rsv3              = %x0 ; 1 bit, MUST be 0

   frame-opcode            = %x0 ; continuation frame
                           / %x1 ; text frame
                           / %x2 ; binary frame
                           / %3-7 ; reserved for further non-control frames
                           / %x8 ; and should
   consider the WebSocket connection closed and close
                           / %x9 ; ping
                           / %xA ; pong
                           / %xB-F ; reserved for further control frames

   frame-masked            = %x0 ; the underlying TCP
   connection.

4.5.2.  Ping

   The Ping frame contains an opcode of 0x9.

   Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in
   response.  It SHOULD do so as soon as is not masked, no frame-masking-key
                           = %x1 ; practical.  Pong frames are
   discussed in Section 4.5.3.

   An endpoint MAY send a Ping frame any time after the connection is masked, frame-masking-key present

   frame-payload-length    = %x00-7D
                           / %x7E frame-payload-length-16
                           / %x7F frame-payload-length-63

   frame-payload-length-16 = %x0000-FFFF

   frame-payload-length-63 = %x0000000000000000-7FFFFFFFFFFFFFFF

   frame-masking-key       = <4>( %0x00-FF ) ; present only if frame-masked
   established and before the connection is 1

   frame-payload-data      = (frame-masked-extension-data
                              frame-masked-application-data)   ; frame-masked 1
                           / (frame-unmasked-extension-data
                              frame-unmasked-application-data) ; frame-masked 0

   frame-masked-extension-data     = *( %x00-FF ) ; to be defined later

   frame-masked-application-data   = *( %x00-FF )

   frame-unmasked-extension-data   = *( %x00-FF ) ; closed.  NOTE: A ping frame
   may serve either as a keepalive, or to be defined later

   frame-unmasked-application-data = *( %x00-FF )

4.3.  Client-to-Server Masking verify that the remote
   endpoint is still responsive.

4.5.3.  Pong

   The client MUST mask all frames sent Pong frame contains an opcode of 0xA.

   Section 4.5.2 details requirements that apply to the server. both Ping and Pong
   frames.

   A server MUST
   close the connection upon receiving Pong frame sent in response to a Ping frame with must have identical
   Application Data as found in the MASK bit set to
   0.  In this case, message body of the Ping frame being
   replied to.

   If an endpoint receives a server Ping frame and has not yet sent Pong
   frame(s) in response to previous Ping frame(s), the endpoint MAY
   elect to send a close Pong frame with a status code
   of 1002 (protocol error) as defined in Section 7.4.1. for only the most recently processed Ping
   frame.

   A masked Pong frame MUST have the field frame-masked set to 1, MAY be sent unsolicited.  This serves as defined
   in Section 4.2.

   The masking key a
   unidirectional heartbeat.  A response to an unsolicited pong is contained completely within not
   expected.

4.6.  Data Frames

   Data frames (e.g. non-control frames) are identified by opcodes where
   the frame, as defined
   in Section 4.2 as frame-masking-key.  It most significant bit of the opcode is used 0.  Currently defined
   opcodes for data frames include 0x1 (Text), 0x2 (Binary).  Opcodes
   0x3-0x7 are reserved for further non-control frames yet to mask be
   defined.

   Data frames carry application-layer or extension-layer data.  The
   opcode determines the interpretation of the data:

   Text

      The payload data defined in the same section is text data encoded as frame-payload-data, which
   includes extension and application data. UTF-8.

   Binary

      The masking key payload data is a 32-bit value chosen at random by arbitrary binary data whose interpretation is
      solely up to the client.
   The masking key MUST be derived from application layer.

4.7.  Examples

   _This section is non-normative._

   o  A single-frame unmasked text message

      *  0x81 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains "Hello")

   o  A single-frame masked text message

      *  0x81 0x85 0x37 0xfa 0x21 0x3d 0x7f 0x9f 0x4d 0x51 0x58
         (contains "Hello")

   o  A fragmented unmasked text message

      *  0x01 0x03 0x48 0x65 0x6c (contains "Hel")

      *  0x80 0x02 0x6c 0x6f (contains "lo")

   o  Ping request and response

      *  0x89 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains a strong source body of entropy, and "Hello",
         but the masking key for a given frame MUST NOT make it simple for a
   server to predict contents of the masking key for body are arbitrary)

      *  0x8a 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains a subsequent frame.

   The masking does not affect body of "Hello",
         matching the length body of the payload data.  To
   convert masked data into ping)

   o  256 bytes binary message in a single unmasked data, or vice versa, the following
   algorithm is applied.  The same algorithm applies regardless frame

      *  0x82 0x7E 0x0100 [256 bytes of the
   direction binary data]

   o  64KiB binary message in a single unmasked frame

      *  0x82 0x7F 0x0000000000010000 [65536 bytes of the translation - e.g. the same steps are applied binary data]

4.8.  Extensibility

   The protocol is designed to
   mask the data as allow for extensions, which will add
   capabilities to unmask the data.

   Octet i of the transformed data ("transformed-octet-i") is the XOR of
   octet i of the original data ("original-octet-i") with octet i modulo
   4 base protocols.  The endpoints of the masking key ("masking-key-octet-j"):

     j                   = i MOD 4
     transformed-octet-i = original-octet-i XOR masking-key-octet-j

   When preparing a masked frame, the client connection
   MUST pick a fresh masking
   key uniformly at random from negotiate the set of allowed 32-bit values.  The
   unpredictability use of any extensions during the masking-nonce is essential to prevent opening
   handshake.  This specification provides opcodes 0x3 through 0x7 and
   0xB through 0xF, the
   author of malicious application extension data from selecting the bytes that
   appear on the wire.

   The payload length, indicated in the framing as frame-payload-length,
   does NOT include field, and the length frame-rsv1, frame-
   rsv2, and frame-rsv3 bits of the masking key.  It frame header for use by extensions.
   The negotiation of extensions is the length discussed in further detail in
   Section 9.1.  Below are some anticipated uses of extensions.  This
   list is neither complete nor proscriptive.

   o  Extension data may be placed in the payload data, e.g. data before the number of bytes following
      application data.

   o  Reserved bits can be allocated for per-frame needs.

   o  Reserved opcode values can be defined.

   o  Reserved bits can be allocated to the masking key.

4.4.  Fragmentation

   The primary purpose opcode field if more opcode
      values are needed.

   o  A reserved bit or an "extension" opcode can be defined which
      allocates additional bits out of fragmentation is the payload data to allow sending define larger
      opcodes or more per-frame bits.

5.  Opening Handshake

5.1.  Client Requirements

   To _Establish a message
   that is of unknown size when the message WebSocket Connection_, a client opens a connection
   and sends a handshake as defined in this section.  A connection is started without having to
   buffer that message.  If messages couldn't be fragmented, then an
   endpoint would have
   defined to buffer the entire message so its length could initially be counted before first byte is sent.  With fragmentation, in a server
   or intermediary may choose CONNECTING state.  A client will need to
   supply a reasonable size buffer, /host/, /port/, /resource name/, and when a /secure/ flag, which
   are the
   buffer is full write components of a fragment WebSocket URI as discussed in Section 3,
   along with a list of /protocols/ and /extensions/ to the network.

   A secondary use-case for fragmentation is for multiplexing, where it be used.
   Additionally, if the client is not desirable for a large message web browser, an /origin/ MUST be
   supplied.

   Clients running in controlled environments, e.g. browsers on one logical channel mobile
   handsets tied to
   monopolize the output channel, so specific carriers, may offload the MUX needs to be free to split management of the message into smaller fragments
   connection to better share another agent on the output
   channel.

   The following rules apply to fragmentation:

   o  An unfragmented message consists of network.  In such a single frame with situation, the FIN
      bit set and an opcode other than 0.

   o  A fragmented message consists of a single frame with
   client for the FIN bit
      clear and an opcode other than 0, followed by zero or more frames
      with purposes of conformance is considered to include both
   the FIN bit clear handset software and any such agents.

   When the opcode set client is to 0, and terminated by _Establish a WebSocket Connection_ given a single frame with the FIN bit set and an opcode
   of 0.  Its
      content is the concatenation (/host/, /port/, /resource name/, and /secure/ flag), along with a
   list of the application data (and any
      extension data that may /protocols/ and /extensions/ to be present) from each of those frames in
      order.  As used, and an example, for a text message sent as three fragments, /origin/ in
   the first fragment would have an opcode case of 0x4 and web browsers, it MUST open a FIN bit
      clear, the second fragment would have connection, send an opcode of 0x0 and a FIN
      bit clear, opening
   handshake, and read the third fragment would have an opcode server's handshake in response.  The exact
   requirements of 0x0 how the connection should be opened, what should be
   sent in the opening handshake, and
      a FIN bit that is set.

   o  Control frames MAY how the server's response should
   be injected interpreted, are as follows in this section.  In the middle following
   text, we will use terms from Section 3 such as "/host/" and "/secure/
   flag" as defined in that section.

   1.  The components of a fragmented
      message.  Control frames themselves MUST NOT be fragmented.

   o  An endpoint the WebSocket URI passed into this algorithm
       (/host/, /port/, /resource name/ and /secure/ flag) MUST be capable valid
       according to the specification of handling control frames WebSocket URIs specified in the
      middle
       Section 3.  If any of a fragmented message.

   o  _Note: if control frames could not be interjected, the latency of components are invalid, the client MUST
       _Fail the WebSocket Connection_ and abort these steps.

   2.  If the client already has a ping, for example, would be very long WebSocket connection to the remote
       host (IP address) identified by /host/ and port /port/ pair, even
       if behind a large message.
      Hence, the requirement of handling control frames in remote host is known by another name, the middle of
      a fragmented message._

   o  A sender MAY create fragments of any size client MUST wait
       until that connection has been established or for non control
      messages.

   o  Clients and servers that connection
       to have failed.  There MUST support receiving both fragmented and
      unfragmented messages.

   o  As control frames cannot be fragmented, an intermediary MUST NOT
      attempt no more than one connection in a
       CONNECTING state.  If multiple connections to change the fragmentation same IP address
       are attempted simultaneously, the client MUST serialize them so
       that there is no more than one connection at a time running
       through the following steps.

       If the client cannot determine the IP address of the remote host
       (for example because all communication is being done through a control frame.

   o  An intermediary
       proxy server that performs DNS queries itself), then the client
       MUST NOT change assume for the fragmentation purposes of this step that each host name
       refers to a message if
      any reserved bit values are used distinct remote host, and should instead limit the meaning
       total number of these values
      is simultaneous connections that are not known established
       to the intermediary.

   o  An intermediary MUST NOT change the fragmentation of any message a reasonably low number (e.g., in the context of a connection where extensions have been
      negotiated Web browser, simultaneous
       pending connections to a.example.com and the intermediary is b.example.com would be
       allowed, but if thirty connections are requested, that may not aware of be
       allowed.  The limit should consider the semantics number of tabs the negotiated extensions.

   o  As user
       has open.

       NOTE: This makes it harder for a consequence script to perform a denial of these rules, all fragments
       service attack by just opening a large number of WebSocket
       connections to a message are remote host.  A server can further reduce the
       load on itself when attacked by making use of this by pausing
       before closing the same type, connection, as set by that will reduce the rate at
       which the client reconnects.

       NOTE: There is no limit to the number of established WebSocket
       connections a client can have with a single remote host.  Servers
       can refuse to accept connections from hosts with an excessive
       number of existing connections, or disconnect resource-hogging
       connections when suffering high load.

   3.  _Proxy Usage_: If the client is configured to use a proxy when
       using the first fragment's opcode.  Since
      Control frames cannot be fragmented, WebSocket protocol to connect to host /host/ and/or
       port /port/, then the type for all fragments in client SHOULD connect to that proxy and ask
       it to open a message MUST be either text or binary, or one of TCP connection to the reserved
      opcodes.

4.5.  Control Frames

   Control frames are identified host given by opcodes where /host/ and the most significant
   bit of
       port given by /port/.

          EXAMPLE: For example, if the opcode is 1.  Currently defined opcodes for control frames
   include 0x8 (Close), 0x9 (Ping), and 0xA (Pong).  Opcodes 0xB-0xF are
   reserved client uses an HTTP proxy for further control frames yet all
          traffic, then if it was to be defined.

   Control frames are used try to communicate state about connect to port 80 on server
          example.com, it might send the websocket.
   Control frames can be interjected in following lines to the middle of a fragmented
   message.

   All control frames MUST have a payload length of 125 bytes or less
   and MUST NOT be fragmented.

4.5.1.  Close

   The Close message contains an opcode of 0x8.

   The Close message MAY contain proxy
          server:

              CONNECT example.com:80 HTTP/1.1
              Host: example.com

          If there was a body (the "application data" portion
   of password, the frame) that indicates a reason for closing, such as an
   endpoint shutting down, an endpoint having received connection might look like:

              CONNECT example.com:80 HTTP/1.1
              Host: example.com
              Proxy-authorization: Basic ZWRuYW1vZGU6bm9jYXBlcyE=

       If the client is not configured to use a message too
   large, or an endpoint having received proxy, then a message that does not conform direct TCP
       connection SHOULD be opened to the format expected host given by /host/ and the
       port given by /port/.

       NOTE: Implementations that do not expose explicit UI for
       selecting a proxy for WebSocket connections separate from other endpoint.  If there is
       proxies are encouraged to use a body, SOCKS proxy for WebSocket
       connections, if available, or failing that, to prefer the first two bytes proxy
       configured for HTTPS connections over the proxy configured for
       HTTP connections.

       For the purpose of proxy autoconfiguration scripts, the body URI to
       pass the function MUST be constructed from /host/, /port/,
       /resource name/, and the /secure/ flag using the definition of a 2-byte integer (in network
   byte order) representing a status code defined
       WebSocket URI as given in Section 7.4.
   Following the 2-byte integer 3.

       NOTE: The WebSocket protocol can be identified in proxy
       autoconfiguration scripts from the body MAY contain UTF-8 encoded data, scheme ("ws:" for unencrypted
       connections and "wss:" for encrypted connections).

   4.  If the interpretation of which is not defined by this specification.
   This data is connection could not necessarily human readable, but may be useful for
   debugging opened, either because a direct
       connection failed or passing information relevant to the script that opened
   the connection.

   The application MUST NOT send because any more data frames after sending a
   close message.

   If proxy used returned an endpoint receives a Close message and that endpoint did not
   previously send a Close message, error,
       then the endpoint client MUST send a Close
   message in response.  It SHOULD do so as soon as is practical.

   After both sending and receiving a close message, an endpoint
   considers _Fail the websocket connection closed, WebSocket Connection_ and SHOULD close abort
       the
   underlying TCP connection. connection attempt.

   5.  If a /secure/ is true, the client and server both send MUST perform a Close message at TLS handshake over
       the same time,
   both endpoints will have sent and received a Close message and should
   consider connection after opening the websocket connection closed and close before sending
       the underlying TCP
   connection.

4.5.2.  Ping

   The Ping message contains an opcode of 0x9.

   Upon receipt of a Ping message, an endpoint handshake data [RFC2818].  If this fails (e.g. the server's
       certificate could not be verified), then the client MUST send a Pong message
   in response.  It SHOULD do so as soon as is practical.  The message
   bodies (i.e. both _Fail
       the Extension data (if any) WebSocket Connection_ and abort the Application
   data) of connection.  Otherwise,
       all further communication on this channel MUST run through the Ping and Pong
       encrypted tunnel.  [RFC5246]

       Clients MUST be use the same.

   An endpoint MAY send a Ping message any time after Server Name Indication extension in the TLS
       handshake.  [RFC6066]

   Once a connection is
   established and before to the server has been established (including a
   connection is closed.  NOTE: A ping
   message may serve either as via a keepalive, proxy or over a TLS-encrypted tunnel), the client
   MUST send an opening handshake to verify that the remote
   endpoint is still responsive.

4.5.3.  Pong server.  The Pong message contains an opcode of 0xA.

   Upon receipt handshake consists
   of a Ping message, an endpoint MUST send HTTP upgrade request, along with a Pong message
   in response.  It SHOULD do so as soon list of required and
   optional headers.  The requirements for this handshake are as is practical.
   follows.

   1.   The message
   bodies (i.e. both the Extension data (if any) and the Application
   data) handshake MUST be a valid HTTP request as specified by
        [RFC2616].

   2.   The Method of the Ping and Pong request MUST be GET and the same.  In the case multiple
   Pings have been received, a Pong HTTP version MUST
        be issued only in response to
   the most recent Ping.

   A Pong message MAY be sent unsolicited.  This serves as a
   unidirectional heartbeat.  A response to an unsolicited pong is not
   expected.

4.6.  Data Frames

   Data frames (e.g. non control frames) are identified by opcodes where
   the most significant bit of at least 1.1.

        For example, if the opcode WebSocket URI is 0.  Currently defined
   opcodes for data frames include 0x1 (Text), 0x2 (Binary).  Opcodes
   0x3-0x7 are reserved for further non-control frames yet to "ws://example.com/chat",
        The first line sent should be
   defined.

   Data frames carry application-layer or extension-layer data. "GET /chat HTTP/1.1"

   3.   The
   opcode determines the interpretation request MUST contain a "Request-URI" as part of the data:

   Text

      The payload data is text data encoded as UTF-8.

   Binary

      The payload data is arbitrary binary data whose interpretation is
      solely up to GET
        method.  This MUST match the application layer.

4.7.  Examples

   _This section is non-normative._

   o  A single-frame unmasked text message

      *  0x81 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains "Hello")

   o  A single-frame masked text message

      *  0x81 0x85 0x37 0xfa 0x21 0x3d 0x7f 0x9f 0x4d 0x51 0x58
         (contains "Hello")

   o  A fragmented unmasked text message

      *  0x01 0x03 0x48 0x65 0x6c (contains "Hel")

      *  0x80 0x02 0x6c 0x6f (contains "lo")

   o  Ping /resource name/ Section 3 (a
        relative URI), or be an absolute URI that, when parsed, has a
        matching /resource name/ as well as matching /host/, /port/, and
        appropriate scheme (ws or wss).

   4.   The request and response

      *  0x89 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains MUST contain a body of "Hello",
         but the contents of "Host" header whose value is equal to
        /host/.

   5.   The request MUST contain an "Upgrade" header whose value is
        equal to "websocket".

   6.   The request MUST contain a "Connection" header whose value MUST
        include the body are arbitrary)

      *  0x8a 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains "Upgrade" token.

   7.   The request MUST include a body of "Hello",
         matching header with the body name "Sec-WebSocket-
        Key".  The value of the ping)

   o  256 bytes binary message in this header MUST be a single unmasked frame

      *  0x82 0x7E 0x0100 [256 bytes nonce consisting of binary data]

   o  64KiB binary message in a single unmasked frame

      *  0x82 0x7F 0x0000000000010000 [65536 bytes of binary data]

4.8.  Extensibility
        randomly selected 16-byte value that has been base64-encoded
        [RFC3548].  The protocol is designed to allow nonce MUST be selected randomly for extensions, which will add
   capabilities to each
        connection.

        NOTE: As an example, if the base protocols.  The endpoints randomly selected value was the
        sequence of a connection
   MUST negotiate bytes 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09
        0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10, the use value of any extensions during the handshake.  This
   specification provides opcodes 0x3 through 0x7 and 0xB through 0xF, header
        would be "AQIDBAUGBwgJCgsMDQ4PEC=="

   8.   The request MUST include a header with the extension data field, and name "Sec-WebSocket-
        Origin" if the frame-rsv1, frame-rsv2, and frame-
   rsv3 bits request is coming from a browser client.  If the
        connection is from a non-browser client, the request MAY include
        this header if the semantics of that client match the frame header use-case
        described here for use by extensions. browser clients.  The negotiation
   of extensions is discussed in further detail in Section 8.1.  Below
   are some anticipated uses value of extensions.  This list is neither
   complete nor proscriptive.

   o  Extension data may this header
        MUST be placed the ASCII serialization of origin of the context in
        which the payload before code establishing the application
      data.

   o  Reserved bits can be allocated for per-frame needs.

   o  Reserved opcode values can be defined.

   o  Reserved bits can connection is running, and MUST
        be allocated to lower-case.  The value MUST NOT contain letters in the opcode field if more opcode
      values are needed.

   o range
        U+0041 to U+005A (i.e.  LATIN CAPITAL LETTER A reserved bit or an "extension" opcode can be to LATIN CAPITAL
        LETTER Z) [I-D.ietf-websec-origin].  The ABNF is as defined which
      allocates additional bits out in
        Section 6.1 of the payload area to define larger
      opcodes or more per-frame bits.

5.  Opening Handshake

5.1.  Client Requirements

   User agents [I-D.ietf-websec-origin].

        As an example, if code is running in controlled environments, e.g. browsers on
   mobile handsets tied www.example.com attempting
        to specific carriers, may offload establish a connection to ww2.example.com, the management value of the connection to another agent on
        header would be "http://www.example.com".

   9.   The request MUST include a header with the network.  In such name "Sec-WebSocket-
        Version".  The value of this header MUST be 8.

   10.  The request MAY include a
   situation, header with the name "Sec-WebSocket-
        Protocol".  If present, this value indicates the subprotocol(s)
        the client wishes to speak, ordered by preference.  The elements
        that comprise this value MUST be non-empty strings with
        characters in the user agent range U+0021 to U+007E not including separator
        characters as defined in [RFC2616], and MUST all be unique
        strings.  The ABNF for the purposes value of conformance this header is
   considered to include both 1#token,
        where the handset software definitions of constructs and any such agents.

   When the user agent is to *establish a WebSocket connection* rules are as given
   either in
        [RFC2616].

   11.  The request MAY include a WebSocket URI /uri/ or header with the constituent components name "Sec-WebSocket-
        Extensions".  If present, this value indicates the protocol-
        level extension(s) the client wishes to speak.  The
        interpretation and format of a URI
   as specified this header is described in
        Section 11, it MUST meet 9.1.

   12.  The request MAY include headers associated with sending cookies,
        as defined by the following requirements.
   In appropriate specifications
        [I-D.ietf-httpstate-cookie].  These headers are referred to as
        _Headers to Send Appropriate Cookies_.

   Once the following text, we will use terms client's opening handshake has been sent, the client MUST
   wait for a response from Section 3 such as
   "/host/" and "/secure/ flag" the server before sending any further data.
   The client MUST validate the server's response as defined in that section. follows:

   1.  The WebSocket URI and its components derived by applying  If the
       steps defined in Section 3.3, or if status code received from the following algorithm was
       supplied with server is not 101, the constituent components
       client handles the response per HTTP procedures.  Otherwise,
       proceed as defined in Section 11
       then those components provided, follows.

   2.  If the response lacks an "Upgrade" header or the "Upgrade" header
       contains a value that is not an ASCII case-insensitive match for
       the value "websocket", the client MUST be valid according to
       Section 3.3. _Fail the WebSocket
       Connection _.

   3.  If any of the requirements are response lacks a "Connection" header or the "Connection"
       header contains a value that is not met, an ASCII case-insensitive
       match for the value "Upgrade", the client MUST fail _Fail the
       WebSocket connection and abort these steps.

   2. Connection_.

   4.  If the user agent already has response lacks a WebSocket connection to "Sec-WebSocket-Accept" header or the
       remote host (IP address) identified by /host/ and port /port/
       pair, even if
       "Sec-WebSocket-Accept" contains a value other than the remote host is known by another name, base64-
       encoded SHA-1 of the user
       agent MUST wait until that connection has been established or for
       that connection to have failed.  There MUST be no more than one
       connection in concatenation of the "Sec-WebSocket-Key" (as
       a CONNECTING state.  If multiple connections to string, not base64-decoded) with the
       same IP address are attempted simultaneously, string "258EAFA5-E914-
       47DA-95CA-C5AB0DC85B11", the user agent client MUST
       serialize them so that there is no more than one connection at a
       time running through _Fail the following steps. WebSocket
       Connection_

   5.  If the user agent cannot determine response includes a "Sec-WebSocket-Extensions" header, and
       this header indicates the IP address use of an extension that was not
       present in the remote
       host (for example because all communication is being done through
       a proxy client' handshake (the server that performs DNS queries itself), then has indicated an
       extension not requested by the user
       agent client), the client MUST assume for _Fail the purposes
       WebSocket Connection_.  (The parsing of this step header to determine
       which extensions are requested is discussed in Section 9.1.)

   If the server's response is validated as provided for above, it is
   said that each host
       name refers _The WebSocket Connection is Established_ and that the
   WebSocket Connection is in the OPEN state.  The _Extensions In Use_
   is defined to be a (possibly empty) string, the value of which is
   equal to a distinct remote host, but should instead limit the total number value of simultaneous connections the |Sec-WebSocket-Extensions| header supplied
   by the server's handshake, or the null value if that are header was not
       established to a reasonably low number (e.g.,
   present in a Web browser, the server's handshake.  The _Subprotocol In Use_ is
   defined to be the number value of tabs the user has open).

       NOTE: This makes it harder for a script to perform a denial of
       service attack by just opening a large number of WebSocket
       connections to a remote host.  A server can further reduce |Sec-WebSocket-Protocol| header in the
       load on itself when attacked by making use of this by pausing
       before closing
   server's handshake, or the connection, as null value if that will reduce header was not present
   in the rate at
       which server's handshake.  Additionally, if any headers in the client reconnects.

       NOTE: There is no limit
   server's handshake indicate that cookies should be set (as defined by
   [I-D.ietf-httpstate-cookie]), these cookies are referred to as
   _Cookies Set During the number of established WebSocket
       connections a user agent can have with a single remote host.
       Servers can refuse Server's Opening Handshake_.

5.2.  Server-side Requirements

   _This section only applies to accept connections from hosts with an
       excessive number servers._

   Servers MAY offload the management of existing connections, or disconnect resource-
       hogging connections when suffering high load.

   3.  _Proxy Usage_: If the user agent is configured connection to use other agents
   on the network, for example load balancers and reverse proxies.  In
   such a proxy
       when using situation, the WebSocket protocol to connect to host /host/
       and/or port /port/, then server for the user agent SHOULD connect purposes of conformance is
   considered to that
       proxy and ask it include all parts of the server-side infrastructure
   from the first device to open a terminate the TCP connection all the way to
   the host given by
       /host/ server that processes requests and the port given by /port/. sends responses.

   EXAMPLE: For example, if the user agent uses a data center might have a server that responds
   to WebSocket requests with an HTTP proxy for
          all traffic, appropriate handshake, and then if it was to try to connect passes
   the connection to port 80 on another server example.com, to actually process the data frames.
   For the purposes of this specification, the "server" is the
   combination of both computers.

5.2.1.  Reading the Client's Opening Handshake

   When a client starts a WebSocket connection, it might send sends its part of the following lines
   opening handshake.  The server must parse at least part of this
   handshake in order to obtain the
          proxy server:

              CONNECT example.com:80 HTTP/1.1
              Host: example.com necessary information to generate
   the server part of the handshake.

   The client's opening handshake consists of the following parts.  If there was
   the server, while reading the handshake, finds that the client did
   not send a password, handshake that matches the connection might look like:

              CONNECT example.com:80 description below, the server
   MUST stop processing the client's handshake, and return an HTTP
   response with an appropriate error code (such as 400 Bad Request).

   1.  An HTTP/1.1
              Host: example.com
              Proxy-authorization: Basic ZWRuYW1vZGU6bm9jYXBlcyE=

       If or higher GET request, including a "Request-URI"
       [RFC2616] that should be interpreted as a /resource name/
       Section 3.

   2.  A "Host" header containing the user agent server's authority.

   3.  A "Sec-WebSocket-Key" header with a base64-encoded value that,
       when decoded, is not configured to use 16 bytes in length.

   4.  A "Sec-WebSocket-Version" header, with a proxy, then value of 8.

   5.  Optionally, a direct
       TCP "Sec-WebSocket-Origin" header.  This header is sent
       by all browser clients.  A connection attempt lacking this header
       SHOULD NOT be opened to the host given by /host/ and interpreted as coming from a browser client.

   6.  Optionally, a "Sec-WebSocket-Protocol" header, with a list of
       values indicating which protocols the port given client would like to speak,
       ordered by /port/.

       NOTE: Implementations that do not expose explicit UI for
       selecting preference.

   7.  Optionally, a proxy for WebSocket connections separate from other
       proxies are encouraged to use "Sec-WebSocket-Extensions" header, with a SOCKS proxy for WebSocket
       connections, if available, or failing that, to prefer the proxy
       configured for HTTPS connections over the proxy configured for
       HTTP connections.

       For the purpose list of proxy autoconfiguration scripts,
       values indicating which extensions the URI client would like to
       pass the function
       speak.  The interpretation of this header is discussed in
       Section 9.1.

   8.  Optionally, other headers, such as those used to send cookies to
       a server.  Unknown headers MUST be constructed from /host/, /port/,
       /resource name/, and the /secure/ flag using ignored.

5.2.2.  Sending the steps to
       construct Server's Opening Handshake

   When a client establishes a WebSocket URI as given in Section 3.2.

       NOTE: The WebSocket protocol can be identified in proxy
       autoconfiguration scripts from the scheme ("ws:" for unencrypted
       connections and "wss:" for encrypted connections).

   4.  If the connection could not be opened, either because to a direct
       connection failed or because any proxy used returned an error,
       then server, the user agent
   server MUST fail complete the following steps to accept the WebSocket connection and abort
   send the connection attempt.

   5. server's opening handshake.

   1.  If /secure/ is true, the user agent MUST server supports encryption, perform a TLS handshake over
       the connection [RFC2818]. connection.  If this fails (e.g. the server's
       certificate could not be verified), then client indicated a host
       name in the user agent MUST fail extended client hello "server_name" extension that
       the WebSocket connection and abort server does not host), then close the connection.  Otherwise, connection; otherwise,
       all further communication on this channel for the connection (including the
       server's handshake) MUST run through the encrypted tunnel.
       [RFC5246]

       User agents MUST use

   2.  Establish the Server Name Indication extension following information:

       /origin/
          The |Sec-WebSocket-Origin| header in the
       TLS handshake.  [RFC6066]

   Once a connection to client's handshake
          indicates the server has been established (including a
   connection via a proxy or over a TLS-encrypted tunnel), origin of the client
   MUST send a handshake to script establishing the server.
          connection.  The handshake consists of an
   HTTP upgrade request, along with a list of required origin is serialized to ASCII and optional
   headers. converted
          to lowercase.  The requirements for server MAY use this handshake are information as follows.

   1.   The handshake MUST be part of
          a valid HTTP request as specified by
        [RFC2616].

   2.   The Method determination of whether to accept the request MUST be GET and incoming connection.
          If the HTTP version MUST
        be at least 1.1.

        For example, if server does not validate the WebSocket URI is "ws://example.com/chat",
        The first line sent should be "GET /chat HTTP/1.1"

   3.   The request MUST contain a "Request-URI" as part of origin, it will accept
          connections from anywhere.  If the GET
        method.  This server does not wish to
          accept this connection, it MUST match return an appropriate HTTP
          error code (e.g. 403 Forbidden) and abort the /resource name/ WebSocket
          handshake described in this section.  For more detail, refer
          to Section 3.

   4. 10.

       /key/
          The request MUST contain a "Host" |Sec-WebSocket-Key| header whose in the client's handshake
          includes a base64-encoded value that, if decoded, is equal 16 bytes
          in length.  This (encoded) value is used in the creation of
          the server's handshake to
        /host/

   5.   The request MUST contain indicate an "Upgrade" header whose value acceptance of the
          connection.  It is
        equal not necessary for the server to "websocket".

   6.   The request MUST contain a "Connection" header whose value MUST
        include base64-
          decode the "Upgrade" token.

   7. "Sec-WebSocket-Key" value.

       /version/
          The request MUST include a |Sec-WebSocket-Version| header with in the name "Sec-WebSocket-
        Key".  The value client's handshake
          includes the version of the WebSocket protocol the client is
          attempting to communicate with.  If this header MUST be a nonce consisting of version does not
          match a
        randomly selected 16-byte value that has been base64-encoded
        [RFC3548].  The nonce version understood by the server, the server MUST be selected randomly for each
        connection.

        NOTE: As
          abort the websocket handshake described in this section and
          instead send an example, if appropriate HTTP error code (such as 426
          Upgrade Required), and a |Sec-WebSocket-Version| header
          indicating the randomly selected value was version(s) the
        sequence server is capable of bytes 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09
        0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10,
          understanding.

       /resource name/
          An identifier for the service provided by the server.  If the
          server provides multiple services, then the value should be
          derived from the resource name given in the client's handshake
          from the Request-URI [RFC2616] of the header
        would be "AQIDBAUGBwgJCgsMDQ4PEC=="

   8.   The request GET method.  If the
          requested service is not available, the server MUST include send an
          appropriate HTTP error code (such as 404 Not Found) and abort
          the WebSocket handshake.

       /subprotocol/
          Either a header with single value or null, representing the name "Sec-WebSocket-
        Origin" if subprotocol
          the request server is coming from a browser client. ready to use.  If the
        connection is server supports multiple
          subprotocols, then the value MUST be derived from a non-browser client, the request MAY include
        this header if client's
          handshake, specifically by selecting one of the semantics values from
          the "Sec-WebSocket-Protocol" field.  The absence of that client match such a
          field is equivalent to the use-case
        described here null value.  The empty string is
          not the same as the null value for browser clients. these purposes, and is not
          a legal value for this field.  The ABNF for the value of this
          header
        MUST be is (token), where the ASCII serialization of origin definitions of the context constructs and
          rules are as given in
        which [RFC2616].

       /extensions/
          A (possibly empty) list representing the code establishing protocol-level
          extensions the connection server is running, and ready to use.  If the server supports
          multiple extensions, then the value MUST be lower-case. derived from the
          client's handshake, specifically by selecting one or more of
          the values from the "Sec-WebSocket-Extensions" field.  The
          absence of such a field is equivalent to the null value.  The
          empty string is not the same as the null value for these
          purposes.  Extensions not listed by the client MUST NOT contain letters be
          listed.  The method by which these values should be selected
          and interpreted is discussed in Section 9.1.

   3.  If the range
        U+0041 to U+005A (i.e.  LATIN CAPITAL LETTER A to LATIN CAPITAL
        LETTER Z) [I-D.ietf-websec-origin].

        As an example, if code is running on www.example.com attempting
        to establish a connection server chooses to ww2.example.com, the value of accept the
        header would be "http://www.example.com".

   9.   The request incoming connection, it MUST include a header
       reply with a valid HTTP response indicating the name "Sec-WebSocket-
        Version". following.

       1.  A 101 response code.  Such a response could look like
           "HTTP/1.1 101 Switching Protocols"

       2.  A "Sec-WebSocket-Accept" header.  The value of this header MUST be 7.

   10.  The request MAY include a header is
           constructed by concatenating /key/, defined above in
           Paragraph 2 of Section 5.2.2, with the name "Sec-WebSocket-
        Protocol".  If present, this value indicates the subprotocol(s) string "258EAFA5-E914-
           47DA-95CA-C5AB0DC85B11", taking the client wishes to speak.  The elements that comprise SHA-1 hash of this
           concatenated value MUST be non-empty strings with characters in the range
        U+0021 to U+007E obtain a 20-byte value, and MUST all be unique strings. base64-
           encoding this 20-byte hash.

           The ABNF for
        the value of this header is 1#(token | quoted-string), where defined as follows:

      accept-value     = base64-value
      base64-value     = *base64-data [ base64-padding ]
      base64-data      = 4base64-character
      base64-padding   = (2base64-character "==") / (3base64-character "=")
      base64-character = ALPHA / DIGIT / "+" / "/"

           NOTE: As an example, if the
        definitions value of constructs and rules are as given in [RFC2616].

   11.  The request MAY include a the "Sec-WebSocket-Key"
           header with in the name "Sec-WebSocket-
        Extensions".  If present, this value indicates client's handshake were
           "dGhlIHNhbXBsZSBub25jZQ==", the protocol-
        level extension(s) server would append the client wishes
           string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" to speak. form the
           string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
           C5AB0DC85B11".  The
        interpretation and format server would then take the SHA-1 hash of
           this header string, giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62
           0x4f 0x16 0x90 0xf6 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe
           0xc4 0xea.  This value is described then base64-encoded, to give the
           value "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", which would be returned
           in the "Sec-WebSocket-Accept" header.

       3.  Optionally, a "Sec-WebSocket-Protocol" header, with a value
           /subprotocol/ as defined in Paragraph 2 of Section 8.1.

   12.  The request MAY include headers associated 5.2.2.

       4.  Optionally, a "Sec-WebSocket-Extensions" header, with sending cookies, a value
           /extensions/ as defined by the appropriate specifications
        [I-D.ietf-httpstate-cookie].

   Once the client's opening handshake has been sent, the client MUST
   wait for in Paragraph 2 of Section 5.2.2.  If
           multiple extensions are to be used, they must all be listed
           in a response from the server before sending any further data.
   The client single Sec-WebSocket-Extensions header.  This header
           MUST validate NOT be repeated.

   This completes the server's response as follows:

   o handshake.  If the status code received from the server is not 101, the client
      handles the response per HTTP procedures.  Otherwise, proceed as
      follows.

   o  If the response lacks an Upgrade header or the Upgrade header
      contains a value that is not an ASCII case-insensitive match for
      the value "websocket", the client MUST fail finishes these
   steps without aborting the WebSocket
      connection.

   o  If handshake, the response lacks a Connection header or server considers
   the Connection header
      contains a value WebSocket connection to be established and that is not an ASCII case-insensitive match for
      the value "Upgrade", the client MUST fail the WebSocket
      connection.

   o  If
   connection is in the response lacks a Sec-WebSocket-Accept header or OPEN state.  At this point, the Sec-
      WebSocket-Accept contains server may begin
   sending (and receiving) data.

6.  Sending and Receiving Data

6.1.  Sending Data

   To _Send a value other than the base64-encoded
      SHA-1 of the concatenation WebSocket Message_ comprising of the Sec-WebSocket-Key (as /data/ over a string,
      not base64-decoded) with the string "258EAFA5-E914-47DA-95CA-
      C5AB0DC85B11", the client MUST fail the WebSocket connection.

   Where
   connection, an endpoint MUST perform the algorithm above requires that a user agent fail following steps.

   1.  The endpoint MUST ensure the WebSocket connection, connection is in the user agent MAY first read an arbitrary
   number OPEN
       state (cf. Section 5.1 and Section 5.2.2.)  If at any point the
       state of further bytes from the WebSocket connection (and then discard them)
   before actually *failing changes, the WebSocket connection*.  Similarly, if a
   user agent can show that endpoint MUST
       abort the bytes read from following steps.

   2.  An endpoint MUST encapsulate the connection so far
   are such that there /data/ in a WebSocket frame as
       defined in Section 4.2.  If the data to be sent is no subsequent sequence of bytes that large, or if
       the
   server can send that would data is not result available in its entirety at the user agent being
   required point the
       endpoint wishes to *fail begin sending the WebSocket connection*, data, the user agent endpoint MAY
   immediately *fail
       alternately encapsulate the WebSocket connection* without waiting for those
   bytes.

   NOTE: data in a series of frames as defined
       in Section 4.4.

   3.  The previous paragraph is intended to make it conforming for
   user agents opcode (frame-opcode) of the first frame containing the data
       MUST be set to implement the algorithm in subtly different ways that
   are equivalent in all ways except appropriate value from Section 4.2 for data
       that they terminate the connection
   at earlier or later points.  For example, it enables an
   implementation is to buffer be interpreted by the entire handshake response before
   checking it, recipient as text or binary
       data.

   4.  The FIN bit (frame-fin) of the last frame containing the data
       MUST be set to verify each field 1 as it defined in Section 4.2.

   5.  If the data is received rather than
   collecting all being sent by the fields and then checking them client, the frame(s) MUST be
       masked as a block.

5.2.  Server-side requirements

   _This section only applies to servers._

   Servers MAY offload defined in Section 4.3.

   6.  If any extensions (Section 9) have been negotiated for the
       WebSocket connection, additional considerations may apply as per
       the management definition of those extensions.

   7.  The frame(s) that have been formed MUST be transmitted over the connection to other agents
       underlying network connection.

6.2.  Receiving Data

   To receive WebSocket data, an endpoint listens on the network, for example load balancers and reverse proxies.  In
   such underlying
   network connection.  Incoming data MUST be parsed as WebSocket frames
   as defined in Section 4.2.  If a situation, control frame (Section 4.5) is
   received, the server for frame MUST be handled as defined by Section 4.5.  Upon
   receiving a data frame (Section 4.6), the purposes of conformance is
   considered to include all parts endpoint MUST note the
   /type/ of the server-side infrastructure
   from data as defined by the first device to terminate Opcode (frame-opcode) from
   Section 4.2.  The _Application Data_ from this frame is defined as
   the TCP connection all /data/ of the way to message.  If the server that processes requests and sends responses.

   EXAMPLE: For example, a data center might have a server frame comprises an unfragmented
   message (Section 4.4), it is said that responds
   to _A WebSocket requests Message Has Been
   Received_ with an appropriate handshake, type /type/ and then passes
   the connection to another server to actually process the data frames.
   For the purposes of this specification, /data/.  If the "server" frame is the
   combination of both computers.

5.2.1.  Reading the client's opening handshake

   When a client starts a WebSocket connection, it sends its part of
   a fragmented message, the
   opening handshake.  The server must parse at least part _Application Data_ of this
   handshake in order to obtain the necessary information subsequent data
   frames is concatenated to generate form the server part of /data/.  When the handshake.

   The client handshake consists last fragment is
   received as indicated by the FIN bit (frame-fin), it is said that _A
   WebSocket Message Has Been Received_ with data /data/ (comprised of
   the following parts.  If concatenation of the server,
   while reading _Application Data_ of the handshake, finds that fragments) and
   type /type/ (noted from the client did not send a
   handshake that matches first frame of the description below, fragmented message).
   Subsequent data frames MUST be interpreted as belonging to a new
   WebSocket Message.

   Extensions (Section 9) MAY change the semantics of how data is read,
   specifically including what comprises a message boundary.

   Data frames received by a server from a client MUST abort be unmasked as
   described in Section 4.3.

7.  Closing the connection

7.1.  Definitions

7.1.1.  Close the WebSocket Connection

   To _Close the WebSocket Connection_, an endpoint closes the
   underlying TCP connection.

   1.  An HTTP/1.1 or higher GET request, including endpoint SHOULD use a "Request-URI"
       [RFC2616] method that should
   cleanly closes the TCP connection, as well as the TLS session, if
   applicable, discarding any trailing bytes that may be interpreted received.  An
   endpoint MAY close the connection via any means available when
   necessary, such as a /resource name/
       Section 3.

   2.  A "Host" header containing when under attack.

   The underlying TCP connection, in most normal cases, SHOULD be closed
   first by the server's authority.

   3.  A "Sec-WebSocket-Key" header with server, so that it holds the TIME_WAIT state and not the
   client (as this would prevent it from re-opening the connection for 2
   MSL, while there is no corresponding server impact as a base64-encoded value that,
       when decoded, TIME_WAIT
   connection is 16 bytes in length.

   4.  A "Sec-WebSocket-Version" header, with immediately reopened upon a value of 7.

   5.  Optionally, new SYN with a "Sec-WebSocket-Origin" header.  This header is sent
       by all browser clients.  A connection attempt lacking this header
       SHOULD NOT be interpreted higher seq
   number).  In abnormal cases (such as coming not having received a TCP Close
   from the server after a browser client.

   6.  Optionally, reasonable amount of time) a "Sec-WebSocket-Protocol" header, with client MAY
   initiate the TCP Close.  As such, when a list of
       values indicating which protocols server is instructed to
   _Close the WebSocket Connection_ it SHOULD initiate a TCP Close
   immediately, and when a client would like is instructed to speak,
       ordered by preference.

   7.  Optionally, do the same, it
   SHOULD wait for a "Sec-WebSocket-Extensions" header, TCP Close from the server.

   As an example of how to obtain a clean closure in C using Berkeley
   sockets, one would call shutdown() with SHUT_WR on the socket, call
   recv() until obtaining a list return value of
       values 0 indicating which extensions that the client would like to
       speak.  The interpretation of this header is discussed peer
   has also performed an orderly shutdown, and finally calling close()
   on the socket.

7.1.2.  Start the WebSocket Closing Handshake

   To _Start the WebSocket Closing Handshake_ with a status code
   (Section 7.4) /code/ and an optional close reason (Section 7.1.6)
   /reason/, an endpoint MUST send a Close control frame, as described
   in Section 8.1.

   8.  Optionally, other headers, such as those used 4.5.1 whose status code is set to send cookies /code/ and whose close
   reason is set to /reason/.  Once an endpoint has both sent and
   received a server.  Unknown headers MUST be ignored.

5.2.2.  Sending Close control frame, that endpoint SHOULD _Close the server's opening handshake

   When a client establishes a
   WebSocket connection to Connection_ as defined in Section 7.1.1.

7.1.3.  The WebSocket Closing Handshake is Started

   Upon either sending or receiving a server, Close control frame, it is said
   that _The WebSocket Closing Handshake is Started_ and that the
   server MUST complete
   WebSocket connection is in the following steps to accept CLOSING state.

7.1.4.  The WebSocket Connection is Closed

   When the underlying TCP connection is closed, it is said that _The
   WebSocket Connection is Closed_ and
   send that the server's opening handshake.

   1. WebSocket connection is
   in the CLOSED state.  If the server supports encryption, perform a TLS tcp connection was closed after the
   WebSocket closing handshake over was completed, the connection. WebSocket connection
   is said to have been closed _cleanly_.

   If this fails (e.g. the client indicated a host
       name in the extended client hello "server_name" extension WebSocket connection could not be established, it is also said
   that
       the server does _The WebSocket Connection is Closed_, but not host), then close the connection; otherwise,
       all further communication for the connection (including the
       server handshake) MUST run through the encrypted tunnel.
       [RFC5246]

   2.  Establish the following information:

       /origin/ cleanly.

7.1.5.  The |Sec-WebSocket-Origin| header WebSocket Connection Close Code

   As defined in the client's handshake
          indicates the origin Section 4.5.1 and Section 7.4, a Close control frame
   may contain a status code indicating a reason for closure.  A closing
   of the script establishing the
          connection.  The origin WebSocket connection may be initiated by either endpoint,
   potentially simultaneously. _The WebSocket Connection Close Code_ is serialized to ASCII and converted
          to lowercase.  The server MAY use this information
   defined as part of
          a determination of whether to accept the incoming connection.
          If status code (Section 7.4) contained in the server does not validate first Close
   control frame received by the origin, it will accept
          connections from anywhere.  For more detail, refer application implementing this protocol.
   If this Close control frame contains no status code, _The WebSocket
   Connection Close Code_ is considered to
          Section 9.

       /key/
          The |Sec-WebSocket-Key| header in the client's handshake
          includes a base64-encoded value that, be 1005.  If _The WebSocket
   Connection is Closed_ and no Close control frame was received by the
   endpoint (such as could occur if decoded, the underlying transport connection
   is 16 bytes
          in length.  This (encoded) value lost), _The WebSocket Connection Close Code_ is used in considered to be
   1006.

   NOTE: Two endpoints may not agree on the creation value of
          the server's handshake to indicate _The WebSocket
   Connection Close Code_.  As an acceptance of example, if the
          connection.  It is remote endpoint sent a
   Close frame but the local application has not necessary for yet read the server to base64-
          decode data
   containing the Sec-WebSocket-Key value.

       /version/
          The |Sec-WebSocket-Version| header in Close frame from its socket's receive buffer, and the client's handshake
          includes
   local application independently decided to close the version of connection and
   send a Close frame, both endpoints will have sent and received a
   Close frame, and will not send further Close frames.  Each endpoint
   will see the WebSocket protocol Connection Close Code sent by the client other end as the
   _WebSocket Connection Close Code_.  As such, it is
          attempting to communicate with.  If this version does possible that the
   two endpoints may not
          match a version understood by agree on the server, value of _The WebSocket Connection
   Close Code_ in the server MUST
          abort case that both endpoints _Start the WebSocket connection.
   Closing Handshake_ independently and at roughly the same time.

7.1.6.  The server MAY send WebSocket Connection Close Reason

   As defined in Section 4.5.1 and Section 7.4, a non-200
          response code with Close control frame
   may contain a |Sec-WebSocket-Version| header status code indicating a reason for closure, followed
   by UTF-8 encoded data, the version(s) interpretation of said data being left to
   the server is capable endpoints and not defined by this protocol.  A closing of understanding.

       /resource name/
          An identifier for the service provided
   WebSocket connection may be initiated by either endpoint, potentially
   simultaneously. _The WebSocket Connection Close Reason_ is defined as
   the UTF-8 encoded data following the status code (Section 7.4)
   contained in the first Close control frame received by the server.
   application implementing this protocol.  If there is no such data in
   the
          server provides multiple services, then Close control frame, _The WebSocket Connection Close Reason_ is
   the value should be
          derived from empty string.

   NOTE: Following the resource name given same logic as noted in Section 7.1.5, two
   endpoints may not agree on _The WebSocket Connection Close Reason_.

7.1.7.  Fail the client's handshake
          from WebSocket Connection

   Certain algorithms and specifications require an endpoint to _Fail
   the Request-URI [RFC2616] of WebSocket Connection_.  To do so, the GET method.

       /subprotocol/
          Either a single value or null, representing client MUST _Close the subprotocol
   WebSocket Connection_, and MAY report the server is ready problem to use.  If the server supports multiple
          subprotocols, then the value MUST user (which
   would be derived from the client's
          handshake, specifically by selecting one of especially useful for developers) in an appropriate manner.

   If _The WebSocket Connection is Established_ prior to the values from point where
   the "Sec-WebSocket-Protocol" field.  The absence of such a
          field endpoint is equivalent required to _Fail the null value.  The empty string is
          not WebSocket Connection_, the same as
   endpoint SHOULD send a Close frame with an appropriate status code
   Section 7.4 before proceeding to _Close the null value for these purposes, and is not WebSocket Connection_.
   An endpoint MAY omit sending a legal value for this field.  The ABNF for Close frame if it believes the value of this
          header other
   side is (token | quoted-string), where the definitions of
          constructs unlikely to be able to receive and rules are as given in [RFC2616].

       /extensions/
          A (possibly empty) list representing process the protocol-level
          extensions close frame,
   due to the server is ready nature of the error that led to use.  If the server supports
          multiple extensions, then WebSocket connection
   being failed in the value first place.  An endpoint MUST be derived NOT continue to
   attempt to process data (including a responding Close frame) from the
          client's handshake, specifically by selecting one or more of
   remote endpoint after being instruted to _Fail the values from WebSocket
   Connection_.

   Except as indicated above or as specified by the "Sec-WebSocket-Extensions" field.  The
          absence of such application layer
   (e.g. a field is equivalent to script using the null value.  The
          empty string is not WebSocket API), clients SHOULD NOT close the same as
   connection.

7.2.  Abnormal Closures

7.2.1.  Client-Initiated Closure

   Certain algorithms, namely during the null value for these
          purposes.  Extensions not listed by opening handshake, require the
   client to _Fail the WebSocket Connection_.  To do so, the client MUST NOT be
          listed.  The method by which these values should be selected
          and interpreted is discussed
   _Fail the WebSocket Connection_ as defined in Section 8.1.

   3. 7.1.7.

   If at any point the server chooses to accept underlying transport layer connection is
   unexpectedly lost, the incoming connection, it client MUST
       reply with a valid HTTP response indicating _Fail the following.

       1.  A 101 response code.  Such a response could look like
           "HTTP/1.1 101 Switching Protocols"

       2.  A "Sec-WebSocket-Accept" header.  The value of this header is
           constructed by concatenating /key/, defined WebSocket Connection_.

   Except as indicated above in
           Paragraph 2 of Section 5.2.2, with the string "258EAFA5-E914-
           47DA-95CA-C5AB0DC85B11", taking or as specified by the SHA-1 hash of this
           concatenated value to obtain application layer
   (e.g. a 20-byte value, and base64-
           encoding this 20-byte hash.

           NOTE: As an example, if the value of script using the "Sec-WebSocket-Key"
           header in WebSocket API), clients SHOULD NOT close the client's handshake were
           "dGhlIHNhbXBsZSBub25jZQ==",
   connection.

7.2.2.  Server-initiated closure

   Certain algorithms require or recommend that the server would append _Abort the
           string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" to form
   WebSocket Connection_ during the opening handshake.  To do so, the
           string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
           C5AB0DC85B11".  The
   server would then take MUST simply _Close the SHA-1 hash WebSocket Connection_ (Section 7.1.1).

7.3.  Normal Closure of
           this string, giving Connections

   Servers MAY close the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62
           0x4f 0x16 0x90 0xf6 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe
           0xc4 0xea.  This value is then base64-encoded, to give WebSocket connection whenever desired.  Clients
   SHOULD NOT close the
           value "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", which would be returned
           in WebSocket connection arbitrarily.  In either
   case, an endpoint initiates a closure by following the "Sec-WebSocket-Accept" header.

       3.  Optionally, procedures to
   _Start the WebSocket Closing Handshake_ (Section 7.1.2).

7.4.  Status Codes

   When closing an established connection (e.g. when sending a "Sec-WebSocket-Protocol" header, with Close
   frame, after the opening handshake has completed), an endpoint MAY
   indicate a value
           /subprotocol/ as defined in Paragraph 2 reason for closure.  The interpretation of Section 5.2.2.

       4.  Optionally, a "Sec-WebSocket-Extensions" header, with this reason by
   an endpoint, and the action an endpoint should take given this
   reason, are left undefined by this specification.  This specification
   defines a value
           /extensions/ as defined in Paragraph 2 set of Section 5.2.2.

   This completes the server's handshake.  If the server finishes these
   steps without aborting the WebSocket connection, pre-defined status codes, and if the client
   does not then fail specifies which ranges
   may be used by extensions, frameworks, and end applications.  The
   status code and any associated textual message are optional
   components of a Close frame.

7.4.1.  Defined Status Codes

   Endpoints MAY use the WebSocket connection, then following pre-defined status codes when sending
   a Close frame.

   1000

      1000 indicates a normal closure, meaning whatever purpose the
      connection is was established and the for has been fulfilled.

   1001

      1001 indicates that an endpoint is "going away", such as a server may begin sending and receiving data.

6.  Error Handling

6.1.  Handling errors in UTF-8
      going down, or a browser having navigated away from the server

   When a client page.

   1002

      1002 indicates that an endpoint is terminating the connection due
      to interpret a byte stream as UTF-8 but finds protocol error.

   1003

      1003 indicates that
   the byte stream an endpoint is not in fact terminating the connection
      because it has received a valid UTF-8 stream, then any bytes
   or sequences type of bytes data it cannot accept (e.g. an
      endpoint that are not valid UTF-8 sequences understands only text data MAY send this if it
      receives a binary message).

   1004

      1004 indicates that an endpoint is terminating the connection
      because it has received a frame that is too large.

   1005

      1005 is a reserved value and MUST NOT be
   interpreted set as a U+FFFD REPLACEMENT CHARACTER.

6.2.  Handling errors status code in UTF-8 from the client

   When a server
      Close control frame by an endpoint.  It is to interpret designated for use in
      applications expecting a byte stream as UTF-8 but finds status code to indicate that
   the byte stream no status
      code was actually present.

   1006

      1006 is not a reserved value and MUST NOT be set as a status code in fact a valid UTF-8 stream, behavior is
   undefined.  A server could close the connection, convert invalid byte
   sequences to U+FFFD REPLACEMENT CHARACTERs, store the data verbatim,
   or perform application-specific processing.  Subprotocols layered on
   the WebSocket protocol might define specific behavior
      Close control frame by an endpoint.  It is designated for servers.

7.  Closing use in
      applications expecting a status code to indicate that the
      connection

7.1.  Definitions

7.1.1. was closed abnormally, e.g. without sending or
      receiving a Close control frame.

7.4.2.  Reserved Status Code Ranges

   0-999

      Status codes in the WebSocket Connection

   To _Close range 0-999 are not used.

   1000-1999

      Status codes in the WebSocket Connection_, an endpoint closes range 1000-1999 are reserved for definition by
      this protocol.

   2000-2999

      Status codes in the
   underlying TCP connection.  An endpoint SHOULD range 2000-2999 are reserved for use a method that
   cleanly closes the TCP connection, as well as by
      extensions.

   3000-3999

      Status codes in the TLS session, if
   applicable, discarding any trailing bytes that may be received.  An
   endpoint range 3000-3999 MAY close the connection via any means available when
   necessary, such as when under attack.

   As an example be used by libraries and
      frameworks.  The interpretation of how to obtain a clean closure these codes is undefined by
      this protocol.  End applications MUST NOT use status codes in this
      range.

   4000-4999

      Status codes in C using Berkeley
   sockets, one would call shutdown() with SHUT_WR on the socket, call
   recv() until obtaining a return value range 4000-4999 MAY be used by application
      code.  The interpretation of 0 indicating that the peer
   has also performed an orderly shutdown, and finally calling close()
   on the socket.

7.1.2.  Start the WebSocket Closing Handshake

   To _start these codes is undefined by this
      protocol.

8.  Error Handling

8.1.  Handling Errors in UTF-8 from the WebSocket closing handshake_, an endpoint MUST send Server

   When a
   Close control frame, client is to interpret a byte stream as described UTF-8 but finds that
   the byte stream is not in Section 4.5.1.  Once an endpoint
   has both sent and received fact a Close control frame, valid UTF-8 stream, then any bytes
   or sequences of bytes that endpoint
   SHOULD _Close the WebSocket Connection_ are not valid UTF-8 sequences MUST be
   interpreted as defined a U+FFFD REPLACEMENT CHARACTER.

8.2.  Handling Errors in Section 7.1.1.

7.1.3.  The WebSocket Connection Is Closed

   When UTF-8 from the underlying TCP connection is closed, it Client

   When a server is said to interpret a byte stream as UTF-8 but finds that _the
   WebSocket connection
   the byte stream is closed_.  If not in fact a valid UTF-8 stream, behavior is
   undefined.  A server could close the tcp connection was closed
   after connection, convert invalid byte
   sequences to U+FFFD REPLACEMENT CHARACTERs, store the WebSocket closing handshake was completed, data verbatim,
   or perform application-specific processing.  Subprotocols layered on
   the WebSocket
   connection is said to have been closed _cleanly_.

7.1.4.  Fail the protocol might define specific behavior for servers.

9.  Extensions

   WebSocket Connection

   Certain algorithms and specifications require a user agent clients MAY request extensions to _fail
   the this specification, and
   WebSocket connection_.  To do so, servers MAY accept some or all extensions requested by the user agent
   client.  A server MUST _Close NOT respond with any extension not requested
   by the
   WebSocket Connection_, client.  If extension parameters are included in negotiations
   between the client and MAY report the problem server, those parameters MUST be chosen in
   accordance with the specification of the extension to which the
   parameters apply.

9.1.  Negotiating Extensions

   A client requests extensions by including a "Sec-WebSocket-
   Extensions" header, which follows the normal rules for HTTP headers
   (see [RFC2616] section 4.2) and the user (which
   would be especially useful for developers) in an appropriate manner.

   Except as indicated above or as specified value of the header is defined by
   the application layer
   (e.g. a script following ABNF.  Note that unlike other section of the document
   this section is using ABNF syntax/rules from [RFC2616].  If a value
   is received by either the WebSocket API), user agents SHOULD NOT close client or the connection.

7.2.  Abnormal closures
7.2.1.  Client-initiated closure

   Certain algorithms, namely server during the initial handshake, require the
   user agent negotiation
   that does not conform to *fail the WebSocket connection*.  To do so, ABNF below, the user
   agent recipient of such
   malformed data MUST _Close immediately _Fail the WebSocket connection_ as previously defined,
   and Connection_.

         extension-list = 1#extension
         extension = extension-token *( ";" extension-param )
         extension-token = registered-token / private-use-token
         registered-token = token
         private-use-token = "x-" token
         extension-param = token [ "=" token ]

   Note that like other HTTP headers, this header MAY report the problem to the user via an appropriate mechanism
   (which would be especially useful for developers).

   Except as indicated above split or as specified by
   combined across multiple lines.  Ergo, the application layer
   (e.g. following are equivalent:

         Sec-WebSocket-Extensions: foo
         Sec-WebSocket-Extensions: bar; baz=2

   is exactly equivalent to

         Sec-WebSocket-Extensions: foo, bar; baz=2

   Any extension-token used MUST either be a script using the WebSocket API), user agents SHOULD NOT close
   the connection.

7.2.2.  Server-initiated closure

   Certain algorithms require registered token
   (registration TBD), or recommend have a prefix of "x-" to indicate a private-
   use token.  The parameters supplied with any given extension MUST be
   defined for that extension.  Note that the server _abort the
   WebSocket connection_ during the opening handshake.  To do so, client is only offering to
   use any advertised extensions, and MUST NOT use them unless the
   server MUST simply _close indicates that it wishes to use the WebSocket connection_ (Section 7.1.1).

7.3.  Normal closure extension.

   Note that the order of connections

   Servers extensions is significant.  Any interactions
   between multiple extensions MAY close be defined in the WebSocket connection whenever desired.  User
   agents SHOULD NOT close documents defining
   the WebSocket connection arbitrarily. extensions.  In
   either case, an endpoint initiates a closure by following the
   procedures to _start the WebSocket closing handshake_
   (Section 7.1.2).

7.4.  Status codes

   When closing an established connection (e.g. when sending a Close
   frame, after absence of such definition, the handshake has completed), an endpoint MAY indicate a
   reason for closure.  The
   interpretation of this reason by an
   endpoint, and is that the action an endpoint should take given this reason,
   are left undefined headers listed by this specification.  This specification defines the client in its
   request represent a set preference of pre-defined status codes, and specifies which ranges may be
   used by extensions, frameworks, and end applications. the headers it wishes to use, with
   the first options listed being most preferable.  The status
   code and any associated textual message are optional components of a
   Close frame.

7.4.1.  Defined Status Codes

   Endpoints MAY use extensions
   listed by the following pre-defined status codes when sending
   a Close frame.

   1000

      1000 indicates a normal closure, meaning whatever purpose server in response represent the
      connection was established extensions actually in
   use for has been fulfilled.

   1001

      1001 indicates that an endpoint is "going away", such as a server
      going down, or a browser having navigated away from a page.

   1002

      1002 indicates that an endpoint is terminating the connection due
      to a protocol error.

   1003

      1003 indicates that an endpoint is terminating connection.  Should the extensions modify the connection
      because it has received a type of data it cannot accept (e.g. an
      endpoint that understands only text and/or
   framing, the order of operations on the data MAY send this if it
      receives a binary message).

   1004

      1004 indicates that an endpoint is terminating should be assumed to be
   the connection
      because it has received a message that is too large.

7.4.2.  Reserved status code ranges

   0-999

      Status codes in same as the range 0-999 are not used.

   1000-1999

      Status codes order in which the range 1000-1999 extensions are reserved for definition by
      this protocol.

   2000-2999

      Status codes listed in the range 2000-2999 are reserved for use by
      extensions.

   3000-3999

      Status codes
   server's response in the range 3000-3999 MAY be used by libraries opening handshake.

   For example, if there are two extensions "foo" and
      frameworks.  The interpretation of these codes is undefined "bar", if the
   header |Sec-WebSocket-Extensions| sent by
      this protocol.  End applications MUST NOT use status codes in this
      range.

   4000-4999

      Status codes in the range 4000-4999 MAY server has the value
   "foo, bar" then operations on the data will be used by application
      code.  The interpretation made as
   bar(foo(data)), be those changes to the data itself (such as
   compression) or changes to the framing thay may "stack".

   Non-normative examples of these codes is undefined by this
      protocol.

8.  Extensions

   WebSocket clients MAY request acceptable extension headers:

      Sec-WebSocket-Extensions: deflate-stream
      Sec-WebSocket-Extensions: mux; max-channels=4; flow-control, deflate-stream
      Sec-WebSocket-Extensions: x-private-extension

   A server accepts one or more extensions to this specification, and
   WebSocket servers MAY accept some by including a |Sec-
   WebSocket-Extensions| header containing one or all more extensions which
   were requested by the client.  A server MUST NOT respond with  The interpretation of any extension not
   parameters, and what constitutes a valid response by a server to a
   requested set of parameters by a client, will be defined by each such
   extension.

9.2.  Known Extensions

   Extensions provide a mechanism for implementations to opt-in to
   additional protocol features.  This section defines the client.  If meaning of
   well-known extensions but implementations MAY use extensions defined
   separately as well.

9.2.1.  Compression

   The registered extension parameters are included in negotiations
   between the client token for this compression extension is
   "deflate-stream".

   The extension does not have any per frame extension data and it does
   not define the server, those parameters MUST be chosen in
   accordance with the specification use of the any WebSocket reserved bits or op codes.

   Senders using this extension MUST apply [RFC1951] encodings to which all
   bytes of the
   parameters apply.

8.1.  Negotiating extensions

   A client requests extensions by data stream following the opening handshake including
   both data and control frames.  The data stream MAY include multiple
   blocks of both compressed and uncompressed types as defined by
   [RFC1951].

   Senders MUST NOT delay the transmission of any portion of a "Sec-WebSocket-
   Extensions" header, which follows WebSocket
   frame because the normal rules deflate encoding of the frame does not end on a
   byte boundary.  The encodings for HTTP headers
   (see [RFC2616] section 4.2) adjacent frames MAY appear in the
   same byte if no delay in transmission is occurred by doing so.

   Historically there have been some confusion and interoperability
   problems around the value specification of compression algorithms.  In this
   specification "deflate-stream" requires a [RFC1951] deflate encoding.
   It MUST NOT be wrapped in any of the header formats often associated
   with RFC 1951 such as "zlib" [RFC1950].  This requirement is defined by given
   special attention with this note because of confusion in this area,
   the following ABNF.  Note that unlike other section presence of some popular open source libraries that create both
   formats under a single API call with confusing naming conventions,
   and the document
   this section is using ABNF syntax/rules from [RFC2616].

         extension-list = 1#extension
         extension = extension-token *( ";" extension-param )
         extension-token = registered-token | private-use-token
         registered-token = token
         private-use-token = "x-" token
         extension-param = token [ "=" ( token | quoted-string ) ]

   Note fact that like other the popular HTTP headers, [RFC2616] specification defines
   "deflate" compression differently than this header MAY be split or
   combined across multiple lines.  Ergo, the following are equivalent:

         Sec-WebSocket-Extensions: foo
         Sec-WebSocket-Extensions: bar; baz=2 specification.

10.  Security Considerations

   While this protocol is exactly equivalent intended to

         Sec-WebSocket-Extensions: foo, bar; baz=2

   Any extension-token be used MUST either by scripts in Web pages,
   it can also be a registered token
   (registration TBD), or have a prefix of "x-" used directly by hosts.  Such hosts are acting on
   their own behalf, and can therefore send fake "Origin" fields,
   misleading the server.  Servers should therefore be careful about
   assuming that they are talking directly to indicate scripts from known
   origins, and must consider that they might be accessed in unexpected
   ways.  In particular, a private-
   use token.  The parameters supplied with server should not trust that any given extension MUST input is
   valid.

   EXAMPLE: For example, if the server uses input as part of SQL
   queries, all input text should be
   defined for that extension.  Note that the client is only offering escaped before being passed to
   use any advertised extensions, and MUST NOT use them unless the
   SQL server, lest the server indicates be susceptible to SQL injection.

   Servers that it wishes are not intended to use process input from any Web page but
   only for certain sites SHOULD verify the extension.

   Note that "Origin" field is an origin
   they expect, and should only respond with the order of extensions corresponding "Sec-
   WebSocket-Origin" if it is significant.  Any interactions
   between multiple extensions MAY be defined an accepted origin.  Servers that only
   accept input from one origin can just send back that value in the documents defining
   the extensions.  In the absence of such definition,
   "Sec-WebSocket-Origin" field, without bothering to check the
   interpretation client's
   value.

   If at any time a server is faced with data that the headers listed it does not
   understand, or that violates some criteria by which the client in its
   request represent a preference server
   determines safety of input, or when the headers it wishes server sees an opening
   handshake that does not correspond to use, with the first options listed being most preferable.  The extensions
   listed by values the server in response represent the extensions actually in
   use for is
   expecting (e.g. incorrect path or origin), the connection.  Should server SHOULD just
   disconnect.  It is always safe to disconnect.

   The biggest security risk when sending text data using this protocol
   is sending data using the extensions modify wrong encoding.  If an attacker can trick
   the server into sending data and/or
   framing, encoded as ISO-8859-1 verbatim (for
   instance), rather than encoded as UTF-8, then the order of operations on attacker could
   inject arbitrary frames into the data should be assumed stream.

   In addition to be endpoints being the same target of attacks via WebSockets,
   other parts of web infrastructure, such as proxies, may be the order in which the extensions are listed in the
   server's response in the opening handshake.

   For example, if there are two extensions "foo"
   subject of an attack.  In particular, an intermediary may interpret a
   WebSocket frame from a client as a request, and "bar", if the
   header |Sec-WebSocket-Extensions| sent by a frame from the
   server has the value
   "foo, bar" then operations on the data will be made as
   bar(foo(data)), be those changes a response to the data itself (such as
   compression) or changes that request.  For instance, an attacker
   could get a browser to the framing thay may "stack".

   Non-normative examples of acceptable extension headers:

      Sec-WebSocket-Extensions: deflate-stream
      Sec-WebSocket-Extensions: mux; max-channels=4; flow-control, deflate-stream
      Sec-WebSocket-Extensions: x-private-extension

   A server accepts one or more extensions by including establish a |Sec-
   WebSocket-Extensions| header containing one or more extensions which
   were requested by connection to its server, get the client.  The interpretation
   browser to send a frame that looks to an intermediary like a GET
   request for a common piece of any extension
   parameters, JavaScript on another domain, and what constitutes send
   back a valid response by frame that is interpreted as a server cacheable response to that
   request, thus poisioning the cache for other users.  To prevent this
   attack, frames sent from clients are masked on the wire with a
   requested set 32-bit
   value, to prevent an attacker from controlling the bits on the wire
   and thus lessen the probability of parameters by an attacker being able to
   construct a client, will frame that can be defined misinterpreted by each such
   extension.

8.2.  Known extensions

   Extensions provide a mechanism for implementations to opt-in to
   additional protocol features.  This section defines the meaning of
   well-known extensions but implementations MAY use extensions defined
   separately proxy as well.

8.2.1.  Compression

   The registered extension token for this compression extension is
   "deflate-stream".

   The extension does not have any per message extension a non-
   WebSocket request.

   As mentioned in Section 8.2, servers must be extremely cautious
   interpreting invalid UTF-8 data and it
   does not define from the use client.  A naive UTF-8
   parsing implementation can result in buffer overflows in the case of any WebSocket reserved bits or op codes.

   Senders
   invalid input data.

   For connections using this extension MUST apply RFC 1951 encodings to all
   bytes of the data stream following TLS (wss: URIs), the handshake including both data
   and control messages.  The data stream MAY include multiple blocks amount of
   both compressed and uncompressed types as defined benefit provided
   by [RFC1951].

   Senders MUST NOT delay TLS depends greatly on the transmission of any portion strength of a WebSocket
   message because the deflate encoding of algorithms negotiated
   during the message does not end on TLS handshake.  To achieve reasonable levels of
   protections, clients should use only Strong TLS algorithms.  "Web
   Security Context: User Interface Guidelines"
   [W3C.REC-wsc-ui-20100812] discusses what constitutes Strong TLS
   algorithms.

11.  IANA Considerations

11.1.  Registration of "ws:" Scheme

   A |ws:| URI identifies a
   byte boundary.  The encodings for adjacent messages MAY appear in the
   same byte if no delay in transmission is occurred by doing so.

   Historically there have been some confusion WebSocket server and resource name.

   URI scheme name.
      ws

   Status.
      Permanent.

   URI scheme syntax.
      In ABNF terms using the terminals from the URI specifications:
      [RFC5234] [RFC3986]

           "ws" ":" hier-part [ "?" query ]

      The <path> [RFC3986] and interoperability
   problems around <query> components form the specification of compression algorithms.  In this
   specification "deflate-stream" requires a [RFC1951] deflate encoding.
   It MUST NOT be wrapped in any of resource name
      sent to the header formats often associated
   with RFC 1951 such as "zlib" [RFC1950].  This requirement is given
   special attention with this note because server to identify the kind of confusion service desired.  Other
      components have the meanings described in RFC3986.

   URI scheme semantics.
      The only operation for this area,
   the presence of some popular scheme is to open source libraries that create both
   formats under a single API call with confusing naming conventions,
   and connection using
      the fact that WebSocket protocol.

   Encoding considerations.
      Characters in the popular HTTP [RFC2616] specification defines
   "deflate" compression differently than this specification.

9.  Security considerations

   While this protocol is intended to be used host component that are excluded by scripts in Web pages,
   it can also the syntax
      defined above MUST be used directly converted from Unicode to ASCII by hosts.  Such hosts are acting on
   their own behalf, and can therefore send fake "Origin" fields,
   misleading applying
      the server.  Servers should therefore be careful about
   assuming that they are talking directly IDNA ToASCII algorithm to scripts from known
   origins, the Unicode host name, with both the
      AllowUnassigned and must consider that they might be accessed in unexpected
   ways.  In particular, a server should not trust that any input is
   valid.

   EXAMPLE: For example, if UseSTD3ASCIIRules flags set, and using the server uses input
      result of this algorithm as part of SQL
   queries, all input text should be escaped before being passed to the
   SQL server, lest host in the server be susceptible to SQL injection.

   Servers URI.  [RFC3490]

      Characters in other components that are not intended to process input excluded by the syntax
      defined above MUST be converted from any Web page but
   only for certain sites SHOULD verify Unicode to ASCII by first
      encoding the "Origin" field is an origin
   they expect, characters as UTF-8 and should only respond with then replacing the
      corresponding "Sec-
   WebSocket-Origin" if it is an accepted origin.  Servers that only
   accept input from one origin can just send back that value bytes using their percent-encoded form as defined in
      the
   "Sec-WebSocket-Origin" field, without bothering to check the client's
   value.

   If at any time URI and IRI specifications.  [RFC3986] [RFC3987]

   Applications/protocols that use this URI scheme name.
      WebSocket protocol.

   Interoperability considerations.
      None.

   Security considerations.
      See "Security considerations" section above.

   Contact.
      HYBI WG <hybi@ietf.org>

   Author/Change controller.
      IETF <iesg@ietf.org>

   References.
      RFC XXXX

11.2.  Registration of "wss:" Scheme

   A |wss:| URI identifies a WebSocket server is faced with data and resource name, and
   indicates that it does not
   understand, or traffic over that violates some criteria by which the server
   determines safety connection is to be protected via
   TLS (including standard benefits of input, or when TLS such as confidentiality,
   integrity, and authentication).

   URI scheme name.
      wss

   Status.
      Permanent.

   URI scheme syntax.
      In ABNF terms using the server sees a handshake that
   does not correspond to terminals from the values URI specifications:
      [RFC5234] [RFC3986]

           "wss" ":" hier-part [ "?" query ]

      The <path> and <query> components form the server is expecting (e.g.
   incorrect path or origin), resource name sent to
      the server SHOULD just disconnect.  It is
   always safe to disconnect. identify the kind of service desired.  Other
      components have the meanings described in RFC3986.

   URI scheme semantics.
      The biggest security risk when sending text data using only operation for this protocol scheme is sending data to open a connection using
      the wrong encoding.  If an attacker can trick WebSocket protocol, encrypted using TLS.

   Encoding considerations.
      Characters in the server into sending data encoded as ISO-8859-1 verbatim (for
   instance), rather than encoded as UTF-8, then host component that are excluded by the attacker could
   inject arbitrary frames into syntax
      defined above MUST be converted from Unicode to ASCII by applying
      the data stream.

   In addition IDNA ToASCII algorithm to endpoints being the target of attacks via WebSockets,
   other parts Unicode host name, with both the
      AllowUnassigned and UseSTD3ASCIIRules flags set, and using the
      result of web infrastructure, such this algorithm as proxies, may be the
   subject of an attack.  In particular, an intermediary may interpret a
   WebSocket message host in the URI.  [RFC3490]

      Characters in other components that are excluded by the syntax
      defined above MUST be converted from a client Unicode to ASCII by first
      encoding the characters as a request, UTF-8 and a message from then replacing the
   server
      corresponding bytes using their percent-encoded form as a response to defined in
      the URI and IRI specification.  [RFC3986] [RFC3987]

   Applications/protocols that request.  For instance, an attacker
   could get a browser to establish a connection to its server, get use this URI scheme name.
      WebSocket protocol over TLS.

   Interoperability considerations.
      None.

   Security considerations.
      See "Security considerations" section above.

   Contact.
      HYBI WG <hybi@ietf.org>

   Author/Change controller.
      IETF <iesg@ietf.org>

   References.
      RFC XXXX

11.3.  Registration of the
   browser to send a message that looks to an intermediary like "WebSocket" HTTP Upgrade Keyword

   This section defines a GET
   request keyword for a common piece of JavaScript on another domain, and send
   back a message that is interpreted registration in the "HTTP Upgrade
   Tokens" registry as per RFC 2817 [RFC2817].

   Name of token.
      WebSocket

   Author/Change controller.
      IETF <iesg@ietf.org>

   Contact.
      HYBI <hybi@ietf.org>

   References.
      RFC XXXX

11.4.  Sec-WebSocket-Key

   This section describes a cacheable response to that
   request, thus poisioning header field for registration in the cache
   Permanent Message Header Field Registry.  [RFC3864]
   Header field name
      Sec-WebSocket-Key

   Applicable protocol
      http

   Status
      standard

   Author/Change controller
      IETF

   Specification document(s)
      RFC XXXX

   Related information
      This header field is only used for other users.  To prevent this
   attack, messages WebSocket opening handshake.

   The |Sec-WebSocket-Key| header is used in the WebSocket opening
   handshake.  It is sent from clients are masked on the wire with a 32-
   bit value, client to prevent an attacker from controlling the bits on server to provide part
   of the
   wire and thus lessen information used by the probability of an attacker being able server to
   construct a message prove that can be misinterpreted by a proxy as it received a non-
   valid WebSocket request.

   As mentioned in Section 6.2, servers must be extremely cautious
   interpreting invalid UTF-8 data from the client.  A naive UTF-8
   parsing implementation can result in buffer overflows in opening handshake.  This helps ensure that the case of
   invalid input data.

10.  IANA considerations

10.1.  Registration of ws: scheme

   A |ws:| URI identifies server
   does not accept connections from non-WebSocket clients (e.g.  HTTP
   clients) that are being abused to send data to unsuspecting WebSocket
   servers.

11.5.  Sec-WebSocket-Extensions

   This section describes a header field for registration in the
   Permanent Message Header Field Registry.  [RFC3864]

   Header field name
      Sec-WebSocket-Extensions

   Applicable protocol
      http

   Status
      standard

   Author/Change controller
      IETF

   Specification document(s)
      RFC XXXX

   Related information
      This header field is only used for WebSocket server and resource name.

   URI scheme name.
      ws

   Status.
      Permanent.

   URI scheme syntax.
      In ABNF terms using opening handshake.

   The |Sec-WebSocket-Extensions| header is used in the terminals WebSocket
   opening handshake.  It is initially sent from the URI specifications:
      [RFC5234] [RFC3986]

           "ws" ":" hier-part [ "?" query ]

      The <path> [RFC3986] and <query> components form client to the resource name
   server, and then subsequently sent to from the server to identify the kind client, to
   agree on a set of service desired.  Other
      components have protocol-level extensions to use for the meanings described in RFC3986.

   URI scheme semantics.
      The only operation duration
   of the connection.

11.6.  WebSocket Extension Name Registry

   This specification requests the creation of a new IANA registry for this scheme is
   WebSocket Extension names to open a connection using be used with the WebSocket protocol.

   Encoding considerations.
      Characters protocol in
   accordance with the host component that are excluded by principles set out in RFC 5226 [RFC5226].

   As part of this registry IANA will maintain the syntax
      defined above MUST following
   information:

   Extension Identifier
      The identifier of the extension, as will be converted from Unicode to ASCII by applying used in the IDNA ToASCII algorithm Sec-
      WebSocket-Extension header registered in Section 11.5 of this
      specification.  The value must conform to the Unicode host name, with both the
      AllowUnassigned and UseSTD3ASCIIRules flags set, and using the
      result requirements for an
      extension-token as defined in Section 9.1 of this algorithm specification.

   Extension Common Name
      The name of the extension, as the host extension is generally referred
      to.

   Extension Definition
      A reference to the document in which the URI.  [RFC3490]

      Characters in other components that are excluded by extension being used with
      the syntax
      defined above MUST WebSocket protocol is defined.

   Known Incompatible Extensions
      A list of extension identifiers with which this extension is known
      to be converted from Unicode incompatible.

   WebSocket Extension names are to ASCII by first
      encoding the characters be subject to First Come First Serve
   as UTF-8 and then replacing per RFC5226 [RFC5226], with the
      corresponding bytes using their percent-encoded form exception of WebSocket Extension
   names whose Extension Identifier matches a private-use-token as
   defined in Section 9.1 (values beginning with "x-").  These Extension
   Identifiers matching private-use-token are reserved for Experimental
   Use as per RFC5226 [RFC5226].

   IANA is asked to add an initial value to the URI and IRI specifications.  [RFC3986] [RFC3987]

   Applications/protocols that use registry (there are no
   known incompatible extensions for this URI scheme name.
      WebSocket protocol.

   Interoperability considerations.
      None.

   Security considerations.
      See "Security considerations" initial entry):

   Extension Identifier |  Extension Common Name |  Extension Definition
 -+---------------------+------------------------+-----------------------
  | deflate-stream      | Deflate Stream         | Section 9.2.1 of this
  |                     | Compression            | document.
 -+---------------------+------------------------+-----------------------

11.7.  Sec-WebSocket-Accept

   This section above.

   Contact.
      HYBI WG <hybi@ietf.org> describes a header field for registration in the
   Permanent Message Header Field Registry.  [RFC3864]

   Header field name
      Sec-WebSocket-Accept

   Applicable protocol
      http

   Status
      standard

   Author/Change controller. controller
      IETF <iesg@ietf.org>

   References.

   Specification document(s)
      RFC XXXX

10.2.  Registration of wss: scheme

   A |wss:| URI identifies a WebSocket server and resource name, and
   indicates that traffic over that connection

   Related information
      This header field is to be encrypted.

   URI scheme name.
      wss

   Status.
      Permanent.

   URI scheme syntax.
      In ABNF terms using the terminals from the URI specifications:
      [RFC5234] [RFC3986]

           "wss" ":" hier-part [ "?" query ] only used for WebSocket opening handshake.

   The <path> and <query> components form |Sec-WebSocket-Accept| header is used in the resource name WebSocket opening
   handshake.  It is sent to from the server to identify the kind of service desired.  Other
      components have client to confirm that
   the meanings described in RFC3986.

   URI scheme semantics.
      The only operation for this scheme server is willing to open initiate the connection.

11.8.  Sec-WebSocket-Origin

   This section describes a connection using header field for registration in the
   Permanent Message Header Field Registry.  [RFC3864]

   Header field name
      Sec-WebSocket-Origin

   Applicable protocol
      http

   Status
      standard

   Author/Change controller
      IETF

   Specification document(s)
      RFC XXXX

   Related information
      This header field is only used for WebSocket protocol, encrypted using TLS.

   Encoding considerations.
      Characters opening handshake.

   The |Sec-WebSocket-Origin| header is used in the host component that are excluded by the syntax
      defined above MUST be converted WebSocket opening
   handshake.  It is sent from Unicode to ASCII by applying the IDNA ToASCII algorithm server to the Unicode host name, with both the
      AllowUnassigned and UseSTD3ASCIIRules flags set, and using client to confirm the
      result
   origin of this algorithm as the host in the URI.  [RFC3490]

      Characters in other components script that are excluded by opened the syntax
      defined above MUST be converted from Unicode connection.  This enables
   clients to ASCII by first
      encoding the characters as UTF-8 and then replacing verify that the
      corresponding bytes using their percent-encoded form as defined in server is willing to serve the URI and IRI specification.  [RFC3986] [RFC3987]

   Applications/protocols script that use this URI scheme name.
      WebSocket protocol over TLS.

   Interoperability considerations.
      None.

   Security considerations.
      See "Security considerations" section above.

   Contact.
      HYBI WG <hybi@ietf.org>

   Author/Change controller.
      IETF <iesg@ietf.org>

   References.
      RFC XXXX

10.3.  Registration of
   opened the "WebSocket" HTTP Upgrade keyword

   Name of token.
      WebSocket

   Author/Change controller.
      IETF <iesg@ietf.org>

   Contact.
      HYBI <hybi@ietf.org>

   References.
      RFC XXXX

10.4.  Sec-WebSocket-Key connection.

11.9.  Sec-WebSocket-Protocol

   This section describes a header field for registration in the
   Permanent Message Header Field Registry.  [RFC3864]

   Header field name
      Sec-WebSocket-Key
      Sec-WebSocket-Protocol

   Applicable protocol
      http

   Status
      standard

   Author/Change controller
      IETF

   Specification document(s)
      RFC XXXX

   Related information
      This header field is only used for WebSocket opening handshake.

   The |Sec-WebSocket-Key| |Sec-WebSocket-Protocol| header is used in the WebSocket opening
   handshake.  It is sent from the client to the server and back from
   the server to provide part the client to confirm the subprotocol of the
   information used by
   connection.  This enables scripts to both select a subprotocol and be
   sure that the server agreed to prove serve that it received a valid subprotocol.

11.10.  WebSocket handshake. Subprotocol Name Registry

   This helps ensure that specification requests the server does not
   accept connections from non-WebSocket clients (e.g.  HTTP clients)
   that are being abused creation of a new IANA registry for
   WebSocket Subprotocol names to send data be used with the WebSocket protocol in
   accordance with the principles set out in RFC 5226 [RFC5226].

   As part of this registry IANA will maintain the following
   information:

   Subprotocol Identifier
      The identifier of the subprotocol, as will be used in the Sec-
      WebSocket-Protocol header registered in Section 11.9 of this
      specification.  The value must conform to unsuspecting the requirements given
      in Paragraph 10 of Paragraph 4 of Section 5.1 of this
      specification, namely the value must be a token as defined by RFC
      2616 [RFC2616].

   Subprotocol Common Name
      The name of the subprotocol, as the subprotocol is generally
      referred to.

   Subprotocol Definition
      A reference to the document in which the subprotocol being used
      with the WebSocket servers.

10.5.  Sec-WebSocket-Extensions protocol is defined.

   WebSocket Subprotocol names are to be subject to First Come First
   Serve as per RFC5226 [RFC5226].

11.11.  Sec-WebSocket-Version

   This section describes a header field for registration in the
   Permanent Message Header Field Registry.  [RFC3864]

   Header field name
      Sec-WebSocket-Extensions
      Sec-WebSocket-Version

   Applicable protocol
      http

   Status
      standard

   Author/Change controller
      IETF

   Specification document(s)
      RFC XXXX

   Related information
      This header field is only used for WebSocket handshake.

   The |Sec-WebSocket-Extensions| header is opening handshake.

   The |Sec-WebSocket-Version| header is used in the WebSocket opening
   handshake.  It is sent from the client to the server to indicate the
   protocol version of the connection.  This enables servers to
   correctly interpret the opening handshake and subsequent data being
   sent from the data, and close the connection if the server cannot
   interpret that data in a safe manner.

11.12.  WebSocket Version Number Registry

   This specification requests the creation of a new IANA registry for
   WebSocket Version Numbers to be used in with the WebSocket
   handshake.  It is initially sent from the client to protocol in
   accordance with the server, and
   then subsequently sent from principles set out in RFC 5226 [RFC5226].

   As part of this registry IANA will maintain the server following
   information:

   Version Number
      The version number to be used in the client, to agree on a
   set Sec-WebSocket-Version as
      specified in Section 5.1 of protocol-level extensions this specification.  The value must be
      a whole number (zero or higher).

   Reference
      The RFC requesting a new version number.

   WebSocket Version Numbers are to be subject to RFC Required as per
   RFC5226 [RFC5226].

   IANA is asked to add initial values to use for the duration registry, with suggested
   numerical values as these have been used in past versions of the
   connection.

10.6.  Sec-WebSocket-Accept this
   protocol.

      Version Number  | Reference
    -+----------------+-----------------------------------------+-
     | 0              + draft-ietf-hybi-thewebsocketprotocol-00 |
    -+----------------+-----------------------------------------+-
     | 1              + draft-ietf-hybi-thewebsocketprotocol-01 |
    -+----------------+-----------------------------------------+-
     | 2              + draft-ietf-hybi-thewebsocketprotocol-02 |
    -+----------------+-----------------------------------------+-
     | 3              + draft-ietf-hybi-thewebsocketprotocol-03 |
    -+----------------+-----------------------------------------+-
     | 4              + draft-ietf-hybi-thewebsocketprotocol-04 |
    -+----------------+-----------------------------------------+-
     | 5              + draft-ietf-hybi-thewebsocketprotocol-05 |
    -+----------------+-----------------------------------------+-
     | 6              + draft-ietf-hybi-thewebsocketprotocol-06 |
    -+----------------+-----------------------------------------+-
     | 7              + draft-ietf-hybi-thewebsocketprotocol-07 |
    -+----------------+-----------------------------------------+-
     | 8              + draft-ietf-hybi-thewebsocketprotocol-08 |
    -+----------------+-----------------------------------------+-

11.13.  WebSocket Close Code Number Registry

   This section describes specification requests the creation of a header field new IANA registry for registration
   WebSocket Connection Close Code Numbers in accordance with the
   Permanent Message Header Field Registry.  [RFC3864]

   Header field name
      Sec-WebSocket-Accept

   Applicable protocol
      http

   Status
      standard

   Author/Change controller
      IETF

   Specification document(s)
   principles set out in RFC XXXX

   Related information
      This header field is only used 5226 [RFC5226].

   As part of this registry IANA will maintain the following
   information:

   Status Code
      The Status Code which denotes a reson for a WebSocket handshake. connection
      closure as per Section 7.4 of this document.  The status code is
      an integer number.

   Meaning
      The meaning of the status code.

   Contact
      A contact for the entity reserving the status code.

   Reference
      The |Sec-WebSocket-Accept| header is used stable document requesting the status codes and defining their
      meaning, required for status codes in the range 1000-2999.

   WebSocket handshake.
   It is sent from the server Close Code Numbers are to the client be subject to confirm that different
   registration requirements depending on their range.  Unless otherwise
   specified, requests are subject to Standards Action as per RFC5226

   [RFC5226].  Requests for status codes for use by this protocol or
   subsequent versions are subject to Standards Action and should be
   granted status codes in the server
   is willing range 1000-1999.  Requests for status
   codes for use by extensions are subject to initiate Specification Required and
   should be granted Status Codes in the connection.

10.7.  Sec-WebSocket-Origin

   This section describes a header field range 2000-2999.  Requests for registration
   status codes for use by libraries and frameworks are subject to First
   Come First Served and should be granted in the
   Permanent Message Header Field Registry.  [RFC3864]

   Header field name
      Sec-WebSocket-Origin

   Applicable protocol
      http

   Status
      standard

   Author/Change controller
      IETF

   Specification document(s)
      RFC XXXX

   Related information
      This header field range 3000-3999.  The
   range of status codes from 4000-4999 is only used designated for Private Use by
   application code.  Requests should indicate whether they are
   requesting status codes for use by the WebSocket handshake.

   The |Sec-WebSocket-Origin| header protocol (or a
   future version of the protocol), by extensions, or by libraries and
   frameworks.

   IANA is asked to add initial values to the registry, with suggested
   numerical values as these have been used in the past versions of this
   protocol.

     |Status Code | Meaning         | Contact       | Reference |
    -+------------+-----------------+---------------+-----------|
     | 1000       | Normal Closure  | hybi@ietf.org | RFC XXXX  |
    -+------------+-----------------+---------------+-----------|
     | 1001       | Going Away      | hybi@ietf.org | RFC XXXX  |
    -+------------+-----------------+---------------+-----------|
     | 1002       | Protocol error  | hybi@ietf.org | RFC XXXX  |
    -+------------+-----------------+---------------+-----------|
     | 1003       | Unsupported Data| hybi@ietf.org | RFC XXXX  |
    -+------------+-----------------+---------------+-----------|
     | 1004       | Frame Too Large | hybi@ietf.org | RFC XXXX  |
    -+------------+-----------------+---------------+-----------|
     | 1005       | No Status Rcvd  | hybi@ietf.org | RFC XXXX  |
    -+------------+-----------------+---------------+-----------|
     | 1006       | Abnormal Closure| hybi@ietf.org | RFC XXXX  |
    -+------------+-----------------+---------------+-----------|

11.14.  WebSocket handshake.
   It is sent from the server to the client to confirm the origin of the
   script that opened the connection. Opcode Registry

   This enables user agents to
   verify that the server is willing to serve the script that opened specification requests the
   connection.

10.8.  Sec-WebSocket-Protocol

   This section describes creation of a header field new IANA registry for registration
   WebSocket Opcodes in accordance with the
   Permanent Message Header Field Registry.  [RFC3864]

   Header field name
      Sec-WebSocket-Protocol

   Applicable protocol
      http

   Status
      standard

   Author/Change controller
      IETF

   Specification document(s) principles set out in RFC XXXX

   Related information
      This header field is only used for WebSocket handshake.
   5226 [RFC5226].

   As part of this registry IANA will maintain the following
   information:

   Opcode
      The |Sec-WebSocket-Protocol| header is used in opcode denotes the frame type of the WebSocket
   handshake.  It frame, as
      defined in Section 4.2.  The status code is sent from the client to the server an integer number
      between 0 and back from 15, inclusive.

   Meaning
      The meaning of the server to opcode code.

   Reference
      The specification requesting the client opcode.

   WebSocket Opcode numbers are subject to confirm the subprotocol of the
   connection.  This enables scripts Standards Action as per
   RFC5226 [RFC5226].

   IANA is asked to both select a subprotocol and be
   sure that the server agreed add initial values to serve that subprotocol.

10.9.  Sec-WebSocket-Version

   This section describes a header field for registration in the
   Permanent Message Header Field Registry.  [RFC3864]

   Header field name
      Sec-WebSocket-Version

   Applicable protocol
      http

   Status
      standard

   Author/Change controller
      IETF

   Specification document(s) registry, with suggested
   numerical values as these have been used in past versions of this
   protocol.

     |Opcode  | Meaning                             | Reference |
    -+--------+-------------------------------------+-----------|
     | 0      | Continuation Frame                  | RFC XXXX  |
    -+--------+-------------------------------------+-----------|
     | 1      | Text Frame                          | RFC XXXX  |
    -+--------+-------------------------------------+-----------|
     | 2      | Binary Frame                        | RFC XXXX

   Related information  |
    -+--------+-------------------------------------+-----------|
     | 8      | Connection Close Frame              | RFC XXXX  |
    -+--------+-------------------------------------+-----------|
     | 9      | Ping Frame                          | RFC XXXX  |
    -+--------+-------------------------------------+-----------|
     | 10     | Pong Frame                          | RFC XXXX  |
    -+--------+-------------------------------------+-----------|

11.15.  WebSocket Framing Header Bits Registry

   This header field is only used specification requests the creation of a new IANA registry for
   WebSocket handshake.

   The |Sec-WebSocket-Version| header is used Framing Header Bits in accordance with the WebSocket
   handshake.  It is sent from the client to the server to indicate the
   protocol version of the connection. principles set
   out in RFC 5226 [RFC5226].  This enables servers to
   correctly interpret the handshake and subsequent data being sent from registry controls assignment of the data,
   bits marked RSV1, RSV2, and close the connection if the server cannot interpret
   that data RSV3 in a safe manner.

11. Section 4.2.

   These bits are reserved for future versions or extensions of this
   specification.

   WebSocket Framing Header Bits assignments are subject to Standards
   Action per RFC 5226 [RFC5226].

12.  Using the WebSocket protocol from other specifications Other Specifications

   The WebSocket protocol is intended to be used by another
   specification to provide a generic mechanism for dynamic author-
   defined content, e.g. in a specification defining a scripted API.

   Such a specification first needs to "establish _Establish a WebSocket
   connection",
   Connection_, providing that algorithm with:

   o  The destination, consisting of a /host/ and a /port/.

   o  A /resource name/, which allows for multiple services to be
      identified at one host and port.

   o  A /secure/ flag, which is true if the connection is to be
      encrypted, and false otherwise.

   o  An ASCII serialization of an origin that is being made responsible
      for the connection.  [I-D.ietf-websec-origin]

   o  Optionally a string identifying a protocol that is to be layered
      over the WebSocket connection.

   The /host/, /port/, /resource name/, and /secure/ flag are usually
   obtained from a URI using the steps to parse a WebSocket URI's
   components.  These steps fail if the URI does not specify a
   WebSocket.

   If a connection can be established, then it is said that the
   "WebSocket connection is established".

   If at any time the connection is to be closed, then the specification
   needs to use the "close _Close the WebSocket connection" algorithm.

   When the connection is closed, for any reason including failure to
   establish the connection in the first place, it is said that the
   "WebSocket connection Connection_ algorithm
   (Section 7.1.1).

   Section 7.1.4 defines when _The WebSocket Connection is closed". Closed_.

   While a connection is open, the specification will need to handle the
   cases when "a _A WebSocket message has been received" with text /data/. Message Has Been Received_ (Section 6.2).

   To send some text data /data/ to an open connection, the specification
   needs to "send /data/ using the WebSocket".

12. _Send a WebSocket Message_ (Section 6.1).

13.  Acknowledgements

   Special thanks are due to Ian Hickson, who was the original author
   and editor of this protocol.  The initial design of this
   specification benefitted from the participation of many people in the
   WHATWG and WHATWG mailing list.  Contributions to that specification
   are not tracked by section, but a list of all who contributed to that
   specification is given in the WHATWG HTML specification at
   http://whatwg.org/html5.

   Special thanks also to John Tamplin for providing a significant
   amount of text for the Data Framing section of this specification.

   Special thanks also to Adam Barth for providing a significant amount
   of text and background research for the Data Masking section of this
   specification.

13.

14.  References

13.1.

14.1.  Normative References

   [ANSI.X3-4.1986]
              American National Standards Institute, "Coded Character
              Set - 7-bit American Standard Code for Information
              Interchange", ANSI X3.4, 1986.

   [FIPS.180-2.2002]
              National Institute of Standards and Technology, "Secure
              Hash Standard", FIPS PUB 180-2, August 2002, <http://
              csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf>.

   [RFC1951]  Deutsch, P., "DEFLATE Compressed Data Format Specification
              version 1.3", RFC 1951, May 1996.

   [RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
              Requirement Levels", BCP 14, RFC 2119, March 1997.

   [RFC2616]  Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
              Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext
              Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.

   [RFC2817]  Khare, R. and S. Lawrence, "Upgrading to TLS Within
              HTTP/1.1", RFC 2817, May 2000.

   [RFC2818]  Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000.

   [RFC3490]  Faltstrom, P., Hoffman, P., and A. Costello,
              "Internationalizing Domain Names in Applications (IDNA)",
              RFC 3490, March 2003.

   [RFC3492]  Costello, A., "Punycode: A Bootstring encoding of Unicode
              for Internationalized Domain Names in Applications
              (IDNA)", RFC 3492, March 2003.

   [RFC3548]  Josefsson, S., "The Base16, Base32, and Base64 Data
              Encodings", RFC 3548, July 2003.

   [RFC3629]  Yergeau, F., "UTF-8, a transformation format of ISO
              10646", STD 63, RFC 3629, November 2003.

   [RFC3864]  Klyne, G., Nottingham, M., and J. Mogul, "Registration
              Procedures for Message Header Fields", BCP 90, RFC 3864,
              September 2004.

   [RFC3986]  Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform
              Resource Identifier (URI): Generic Syntax", STD 66,
              RFC 3986, January 2005.

   [RFC3987]  Duerst, M. and M. Suignard, "Internationalized Resource
              Identifiers (IRIs)", RFC 3987, January 2005.

   [RFC4086]  Eastlake, D., Schiller, J., and S. Crocker, "Randomness
              Requirements for Security", BCP 106, RFC 4086, June 2005.

   [RFC5246]  Dierks, T. and E. Rescorla, "The Transport Layer Security
              (TLS) Protocol Version 1.2", RFC 5246, August 2008.

   [RFC6066]  Eastlake, D., "Transport Layer Security (TLS) Extensions:
              Extension Definitions", RFC 6066, January 2011.

   [RFC4648]  Josefsson, S., "The Base16, Base32, and Base64 Data
              Encodings", RFC 4648, October 2006.

   [RFC5226]  Narten, T. and H. Alvestrand, "Guidelines for Writing an
              IANA Considerations Section in RFCs", BCP 26, RFC 5226,
              May 2008.

   [RFC5234]  Crocker, D. and P. Overell, "Augmented BNF for Syntax
              Specifications: ABNF", STD 68, RFC 5234, January 2008.

13.2.

14.2.  Informative References

   [WSAPI]    Hickson, I., "The Web Sockets API", August 2010,
              <http://dev.w3.org/html5/websockets/>.

   [I-D.ietf-httpstate-cookie]
              Barth, A., "HTTP State Management Mechanism",
              draft-ietf-httpstate-cookie-20 (work in progress),
              December 2010.

   [I-D.ietf-websec-origin]
              Barth, A., "The Web Origin Concept",
              draft-ietf-websec-origin-00 (work in progress),
              December 2010.

   [RFC1950]  Deutsch, L. and J-L. Gailly, "ZLIB Compressed Data Format
              Specification version 3.3", RFC 1950, May 1996.

   [RFC5321]  Klensin, J., "Simple Mail Transfer Protocol", RFC 5321,
              October 2008.

   [RFC6202]  Loreto, S., Saint-Andre, P., Salsano, S., and G. Wilkins,
              "Known Issues and Best Practices for the Use of Long
              Polling and Streaming in Bidirectional HTTP", RFC 6202,
              April 2011.

   [W3C.REC-wsc-ui-20100812]
              Saldhana, A. and T. Roessler, "Web Security Context: User
              Interface Guidelines", World Wide Web Consortium
              Recommendation REC-wsc-ui-20100812, August 2010,
              <http://www.w3.org/TR/2010/REC-wsc-ui-20100812>.

Author's Address

   Ian Fette
   Google, Inc.

   Email: ifette+ietf@google.com
   URI:   http://www.ianfette.com/