Qore WebSocketUtil Module Reference  1.4.1
WebSocketUtil Namespace Reference

the WebSocketUtil namespace contains all the definitions in the WebSocketUtil module More...

Classes

hashdecl  WsMsgInfo
 WebSocket message info. More...
 

Functions

binary ws_encode_message (data msg, int op=-1, *bool masked, bool fin=True)
 encodes a message for sending over a websocket socket
 
string ws_get_response_key (string key)
 returns a string response key from the binary key and the WebSocket GUID value More...
 
hash< WsMsgInfows_read_message (Socket sock, *timeout to)
 read and decode a message from a socket More...
 

Variables

const WS_FIN = (1 << 7)
 the final fragment in a message
 
const WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
 WebSocket GUID.
 
const WSCC_AbnormalClosure = 1006
 "Abnormal Closure" code
 
const WSCC_GoingAway = 1001
 "Going Away" code
 
const WSCC_InternalServerError = 1011
 "Internal Server Error" code
 
const WSCC_InvalidData = 1007
 "Invalid Frame Payload Data" code
 
const WSCC_MandatoryExt = 1010
 "Mandatory Ext." code
 
const WSCC_MessageTooBig = 1009
 "Message Too Big" code
 
const WSCC_NormalClosure = 1000
 "Normal Closure" code
 
const WSCC_NoStatusRcvd = 1005
 "No Status Rcvd" code
 
const WSCC_PolicyViolation = 1008
 "Policy Violation" code
 
const WSCC_ProtocolError = 1002
 "Protocol Error" code
 
const WSCC_TlsHandshake = 1015
 "TLS Handshake" code
 
const WSCC_UnsupportedData = 1003
 "Unsupported Data" code
 
const WSCCMap
 maps from close codes to text descriptions
 
const WSOP_Binary = 0x2
 binary frame opcode
 
const WSOP_Close = 0x8
 connection code opcode
 
const WSOP_Continuation = 0x0
 continuation frame opcode
 
const WSOP_Ping = 0x9
 ping opcode
 
const WSOP_Pong = 0xa
 pong opcode
 
const WSOP_Text = 0x1
 text frame opcode
 
const WSOPMap
 maps from opcodes to text descriptions
 

Detailed Description

the WebSocketUtil namespace contains all the definitions in the WebSocketUtil module

Function Documentation

◆ 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
keythe 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_read_message()

hash<WsMsgInfo> WebSocketUtil::ws_read_message ( Socket  sock,
*timeout  to 
)

read and decode a message from a socket

Example:
hash<WsMsgInfo> h = ws_read_message(sock);
Parameters
sockthe Socket object to receive the message
toan optional read timeout
Returns
a hash with the following keys:
  • op: the operation code (one of WebSocket 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 WebSocket Close Codes); only included if op is WSOP_Close