0% found this document useful (0 votes)
25 views

WebSocket Data Frame Explained by @ErickWendel

The document explains the format and structure of WebSocket frames. It details each byte and bit in the frame, describing what information is contained in different parts of the frame like the FIN bit, opcode, payload length, masking key, and encoded payload data.

Uploaded by

ranjana deore
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

WebSocket Data Frame Explained by @ErickWendel

The document explains the format and structure of WebSocket frames. It details each byte and bit in the frame, describing what information is contained in different parts of the frame like the FIN bit, opcode, payload length, masking key, and encoded payload data.

Uploaded by

ranjana deore
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Follow me: @erickwendel_

Frame Data Example


Message Byte Array
MDN 129 131 61 84 35 6 112 16 109

Buffer BIT REPRESENTS


Indicates that this is the final fragment in a message. The first
0 FIN
fragment MAY also be the final fragment.
1 RSV1
2 RSV2
1 BYTE 3 RSV3
4 Defines the interpretation of the payload data. 0x01: this frame includes utf-8 text data.
5 0x08: this frame terminates the connection.
OPCODE
6
7
0 MASK Indicator 1 or 0 If set to 1, a masking key is present and "Payload data" is masked
1 <=125, 126 or 127 >
2 131 = 0x83=0000011 If this value is between 0 and 125, then it is the length of message.
3 If it is 126, the following 2 bytes (16-bit unsigned integer) are the length.
2 BYTE
4 Payload Length If it is 127, the following 8 bytes (64-bit unsigned integer) are the length.
5
6
7
0
1
2
3
3 BYTE
4
5
6
7
Content Length if it's 126 - 16-bit unsined integer
0
1
2
3
4 BYTE
4
5
6
7
mask key if indicator == 1
0
1
2
3
5 BYTE
4
5
6
7
0
1
2
3
6 BYTE
4
5
6
7
all remaining bytes are the encoded payload data Content Length if it's 127 - 64-bit unsined integer
0
1
2
3
7 BYTE
4
5
6
7
0
1
2
3
8 BYTE
4
5
6
7
0
1
2
3
9 BYTE
4
5
6
7
0
1
2
3
10 BYTE
4
5
6
7
Follow me: @erickwendel_

Frame Data Example


Message Byte Array
MDN 129 131 61 84 35 6 112 16 109

Buffer BIT REPRESENTS


0 FIN
1 RSV1
2 RSV2
3 RSV3
1 BYTE
4
5
OPCODE
6
7

0 MASK Indicator

1
2
2 BYTE
3
4 Payload Length
5
6
7
0
1
2
3
3 BYTE
4
5
6
7
0
1
2
3
4 BYTE
4
5
6
7
all remaining bytes are the encoded payload data
0
1
2
3
5 BYTE
4
5
6
7
0
1
2
3
6 BYTE
4
5
6
7
Follow me: @erickwendel_

Frame Data Example


Message Byte Array
MDN 129 131 61 84 35 6 112 16 109

Buffer BIT REPRESENTS


0 FIN
1 RSV1
2 RSV2
3 RSV3
1 BYTE
4
5
OPCODE
6
7
0 MASK Indicator
1
2
3
2 BYTE
4 Payload Length
5
6
7
0
1
2
3
3 BYTE
4
5
6
7
0
1
2
3
4 BYTE
4
5
6
7
mask key if indicator == 1
0
1
2
3
5 BYTE
4
5
6
7
0
1
2
3
6 BYTE
4
5
6
7
0
1
2
3
7 BYTE
4
5
6
7
0
1
2
3
8 BYTE
4
5
6
7
all remaining bytes are the encoded payload data
0
1

9 BYTE
all remaining bytes are the encoded payload data

2
3
9 BYTE
4
5
6
7
0
1
2
3
10 BYTE
4
5
6
7
Follow me: @erickwendel_

Frame Data Example


Message Byte Array
MDN 129 131 61 84 35 6 112 16 109

Buffer BIT REPRESENTS


0 FIN
1 RSV1
2 RSV2
3 RSV3
1 BYTE
4
5
OPCODE
6
7
0 MASK Indicator
1
2
3
2 BYTE
4 Payload Length
5
6
7
0
1
2
3
3 BYTE
4
5
6
7
Content Length if it's 126 - 16-bit unsined integer
0
1
2
3
4 BYTE
4
5
6
7
0
1
2
3
5 BYTE
4
5
6
7
0
1
2
3
6 BYTE
4
5
6
7
mask key if indicator == 1
0
1
2
3
7 BYTE
4
5
6
7
0
1
2
3
8 BYTE
4
5
6
7
0
1

9 BYTE
2
3
9 BYTE
4
5
6
7
all remaining bytes are the encoded payload data
0
1
2
3
10 BYTE
4
5
6
7
Follow me: @erickwendel_

Frame Data Example


Message Byte Array
MDN 129 131 61 84 35 6 112 16 109

Buffer BIT REPRESENTS


0 FIN
1 RSV1
2 RSV2
3 RSV3
1 BYTE
4
5
OPCODE
6
7
0 MASK Indicator
1
2
3
2 BYTE
4 Payload Length
5
6
7
0
1
2
3
3 BYTE
4
5
6
7
Content Length if it's 126 - 16-bit unsined integer
0
1
2
3
4 BYTE
4
5
6
7
0
1
2
3
5 BYTE
4
5
6
7
0
1
2
3
6 BYTE
4
5
6
7
all remaining bytes are the encoded payload data
0
1
2
3
7 BYTE
4
5
6
7
0
1
2
3
8 BYTE
4
5
6
7
Follow me: @erickwendel_

Frame Data Example


Message Byte Array
MDN 129 131 61 84 35 6 112 16 109

Buffer BIT REPRESENTS


0 FIN
1 RSV1
2 RSV2
3 RSV3
1 BYTE
4
5
OPCODE
6
7
0 MASK Indicator
1
2
3
2 BYTE
4 Payload Length
5
6
7
0
1
2
3
3 BYTE
4
5
6
7
0
1
2
3
4 BYTE
4
5
6
7
0
1
2
3
5 BYTE
4
5
6
7
0
1
2
3
6 BYTE
4
5
6
7
Content Length if it's 127 - 64-bit unsined integer
0
1
2
3
7 BYTE
4
5
6
7
0
1
2
3
8 BYTE
4
5
6
7
0
1

9 BYTE
2
3
9 BYTE
4
5
6
7
0
1
2
3
10 BYTE
4
5
6
7
0
1
2
3
11 BYTE
4
5
6
7
0
1
2
3
12 BYTE
4
5
6
7
mask key if indicator == 1
0
1
2
3
13 BYTE
4
5
6
7
0
1
2
3
14 BYTE
4
5
6
7
0
1
2
3
15 BYTE
4
5
6
7
all remaining bytes are the encoded payload data
0
1
2
3
16 BYTE
4
5
6
7
Follow me: @erickwendel_

Frame Data Example


Message Byte Array
MDN 129 131 61 84 35 6 112 16 109

Buffer BIT REPRESENTS


0 FIN
1 RSV1
2 RSV2
3 RSV3
1 BYTE
4
5
OPCODE
6
7
0 MASK Indicator
1
2
3
2 BYTE
4 Payload Length
5
6
7
0
1
2
3
3 BYTE
4
5
6
7
0
1
2
3
4 BYTE
4
5
6
7
0
1
2
3
5 BYTE
4
5
6
7
0
1
2
3
6 BYTE
4
5
6
7
Content Length if it's 127 - 64-bit unsined integer
0
1
2
3
7 BYTE
4
5
6
7
0
1
2
3
8 BYTE
4
5
6
7
0
1

9 BYTE
2
3
9 BYTE
4
5
6
7
0
1
2
3
10 BYTE
4
5
6
7
0
1
2
3
11 BYTE
4
5
6
7
0
1
2
3
12 BYTE
4
5
6
7
all remaining bytes are the encoded payload data
0
1
2
3
13 BYTE
4
5
6
7
0
1
2
3
14 BYTE
4
5
6
7

You might also like