the WebSocketUtil namespace contains all the definitions in the WebSocketUtil module
More...
|
| binary | ws_encode_message (data msg, int op, soft< bool > masked, bool fin, int rsv_bits) |
| | encodes a message for sending over a websocket socket
|
| |
| soft< int > | ws_get_frame_size (binary buf) |
| | Returns the total size needed for a complete WebSocket frame, or NOTHING if not enough header data.
|
| |
| string | ws_get_response_key (string key) |
| | returns a string response key from the binary key and the WebSocket GUID value
|
| |
| hash< WsMsgInfo > | ws_parse_frame (binary buf, soft< string > encoding) |
| | Parses a WebSocket frame from binary data.
|
| |
| hash< WsMsgInfo > | ws_read_message (Socket sock, soft< timeout > to) |
| | read and decode a message from a socket
|
| |
|
|
const auto | WS_FIN = ... |
| | the final fragment in a message
|
| |
|
const auto | WS_GUID = ... |
| | WebSocket GUID.
|
| |
| const auto | WS_RSV1 = ... |
| | RSV1 bit - used by permessage-deflate extension.
|
| |
| const auto | WS_RSV2 = ... |
| | RSV2 bit - reserved for extensions.
|
| |
| const auto | WS_RSV3 = ... |
| | RSV3 bit - reserved for extensions.
|
| |
|
const auto | WSCC_AbnormalClosure = ... |
| | "Abnormal Closure" code
|
| |
|
const auto | WSCC_GoingAway = ... |
| | "Going Away" code
|
| |
|
const auto | WSCC_InternalServerError = ... |
| | "Internal Server Error" code
|
| |
|
const auto | WSCC_InvalidData = ... |
| | "Invalid Frame Payload Data" code
|
| |
|
const auto | WSCC_MandatoryExt = ... |
| | "Mandatory Ext." code
|
| |
|
const auto | WSCC_MessageTooBig = ... |
| | "Message Too Big" code
|
| |
|
const auto | WSCC_NormalClosure = ... |
| | "Normal Closure" code
|
| |
|
const auto | WSCC_NoStatusRcvd = ... |
| | "No Status Rcvd" code
|
| |
|
const auto | WSCC_PolicyViolation = ... |
| | "Policy Violation" code
|
| |
|
const auto | WSCC_ProtocolError = ... |
| | "Protocol Error" code
|
| |
|
const auto | WSCC_TlsHandshake = ... |
| | "TLS Handshake" code
|
| |
|
const auto | WSCC_UnsupportedData = ... |
| | "Unsupported Data" code
|
| |
|
const auto | WSCCMap = ... |
| | maps from close codes to text descriptions
|
| |
|
const auto | WSOP_Binary = ... |
| | binary frame opcode
|
| |
|
const auto | WSOP_Close = ... |
| | connection code opcode
|
| |
|
const auto | WSOP_Continuation = ... |
| | continuation frame opcode
|
| |
|
const auto | WSOP_Ping = ... |
| | ping opcode
|
| |
|
const auto | WSOP_Pong = ... |
| | pong opcode
|
| |
|
const auto | WSOP_Text = ... |
| | text frame opcode
|
| |
|
const auto | WSOPMap = ... |
| | maps from opcodes to text descriptions
|
| |
the WebSocketUtil namespace contains all the definitions in the WebSocketUtil module
◆ ws_encode_message()
| binary WebSocketUtil::ws_encode_message |
( |
data |
msg, |
|
|
int |
op, |
|
|
soft< bool > |
masked, |
|
|
bool |
fin, |
|
|
int |
rsv_bits |
|
) |
| |
encodes a message for sending over a websocket socket
- Parameters
-
| msg | the message to encode |
| op | the opcode to use; if -1 (the default), the opcode is determined from the message type |
| masked | if True, the message is masked with a random mask |
| fin | if True (the default), the FIN bit is set |
| rsv_bits | optional RSV bits to set (bitmask of WS_RSV1, WS_RSV2, WS_RSV3); these are used by extensions like permessage-deflate |
- Returns
- the encoded WebSocket frame as binary data
- Since
- WebSocketUtil 1.5 added the
rsv_bits parameter
◆ ws_get_frame_size()
| soft< int > WebSocketUtil::ws_get_frame_size |
( |
binary |
buf | ) |
|
Returns the total size needed for a complete WebSocket frame, or NOTHING if not enough header data.
- Parameters
-
| buf | the buffer containing at least the beginning of a WebSocket frame |
- Returns
- the total number of bytes needed for a complete frame, or NOTHING if the buffer doesn't contain enough data to determine the frame size (need at least 2 bytes for header, plus extended length bytes if applicable)
- Since
- WebSocketUtil 1.7
◆ ws_get_response_key()
| string WebSocketUtil::ws_get_response_key |
( |
string |
key | ) |
|
returns a string response key from the binary key and the WebSocket GUID value
- Parameters
-
| key | the base64-encoded key received in the Sec-WebSocket-Key header |
- Returns
- the base64-encoded string value for the
Sec-WebSocket-Accept header
- Since
- WebSocketUtil 1.4
◆ ws_parse_frame()
| hash< WsMsgInfo > WebSocketUtil::ws_parse_frame |
( |
binary |
buf, |
|
|
soft< string > |
encoding |
|
) |
| |
Parses a WebSocket frame from binary data.
- Parameters
-
| buf | the binary data containing the WebSocket frame |
| encoding | the character encoding to use for text messages |
- Returns
- a hash with the following keys:
op: the operation code (one of ws_op_codes)
msg: the message data received, if any
masked: True if the data was masked
close: for close messages, the close code
fin: True if this is the final frame in a message
rsv1: the RSV1 bit (used by extensions like permessage-deflate)
rsv2: the RSV2 bit (reserved for extensions)
rsv3: the RSV3 bit (reserved for extensions)
info: user-defined info; may include debug-only metadata
- Exceptions
-
| WEBSOCKET-ERROR | if the buffer is too short to contain a valid frame |
- Note
- This function is used for HTTP/2 WebSocket where frame data comes from HTTP/2 DATA frames rather than directly from the socket
- Since
- WebSocketUtil 1.6
◆ ws_read_message()
| hash< WsMsgInfo > WebSocketUtil::ws_read_message |
( |
Socket |
sock, |
|
|
soft< timeout > |
to |
|
) |
| |
read and decode a message from a socket
- Example:
hash<WsMsgInfo> h = ws_read_message(sock);
- Parameters
-
| sock | the Socket object to receive the message |
| to | an optional read timeout |
- Returns
- a hash with the following keys:
op: the operation code (one of opcodes)
masked a boolean flag indicating if the message was masked or not
msg: the message received; if a CLOSE opcode is received (see WSOP_Close) then any close message is decoded and included here in text form
close: the close code (one of closecodes); only included if op is WSOP_Close
fin: True if this is the final frame in a message
rsv1: the RSV1 bit (used by extensions like permessage-deflate)
rsv2: the RSV2 bit (reserved for extensions)
rsv3: the RSV3 bit (reserved for extensions)
info: user-defined info; may include debug-only metadata
- Since
- WebSocketUtil 1.5 added
rsv1, rsv2, rsv3 fields
◆ WS_RSV1
| const auto WebSocketUtil::WS_RSV1 = ... |
RSV1 bit - used by permessage-deflate extension.
- Since
- WebSocketUtil 1.5
◆ WS_RSV2
| const auto WebSocketUtil::WS_RSV2 = ... |
◆ WS_RSV3
| const auto WebSocketUtil::WS_RSV3 = ... |