• 累计撰写 781 篇文章
• 累计创建 1 个标签
• 累计收到 1 条评论

# 数据帧

2022-01-09 / 0 评论 / 0 点赞 / 39 阅读 / 4,049 字

This wire format for the data transfer part is described by the ABNF [RFC5234] given in detail in this section.
 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
+-+-+-+-+-------+-+-------------+-------------------------------+
|I|S|S|S|  (4)  |A|     (7)     |             (16/64)           |
|N|V|V|V|       |S|             |   (if payload len==126/127)   |
| |1|2|3|       |K|             |                               |
+-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
+ - - - - - - - - - - - - - - - +-------------------------------+
+-------------------------------+-------------------------------+
+-------------------------------- - - - - - - - - - - - - - - - +
:                     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 that 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 _Fail the WebSocket Connection_.
Opcode: 4 bits
  Defines the interpretation of the &quot;Payload data&quot;.  If an unknown opcode is received, the receiving endpoint MUST _Fail the WebSocket Connection_.  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


  Defines whether the &quot;Payload data&quot; is masked.  If set to 1, a
the &quot;Payload data&quot; as perSection 5.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 &quot;Payload data&quot;, 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.  Note that
in all cases, the minimal number of bytes MUST be used to encode
the length, for example, the length of a 124-byte-long string
can't be encoded as the sequence 126, 0, 124.  The payload length
is the length of the &quot;Extension data&quot; + the length of the
&quot;Application data&quot;.  The length of the &quot;Extension data&quot; may be
zero, in which case the payload length is the length of the
&quot;Application data&quot;.

  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.  SeeSection 5.3 for further information on client-


  The &quot;Payload data&quot; is defined as &quot;Extension data&quot; concatenated
with &quot;Application data&quot;.


Extension data: x bytes

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


Application data: y bytes

  Arbitrary &quot;Application data&quot;, taking up the remainder of the frame
after any &quot;Extension data&quot;.  The length of the &quot;Application data&quot;
is equal to the payload length minus the length of the &quot;Extension
data&quot;.</div></div>
<div style="padding-left: 1.5em; display: flex; flex-direction: column;">

0