Introduction to the WebSocketClient Module
The WebSocketClient module provides client support for RFC-6455 based WebSocket protocol implementations in Qore.
To use this module, use "%requires WebSocketClient"
in your code.
This module automatically uses the WebSocketUtil module for encoding and decoding web socket messages.
All the public symbols in the module are defined in the WebSocketClient namespace.
Currently the module provides the following classes:
- WebSocketClient: the web socket client class
- WebSocketConnectionObject: the web socket connection class (based on the ConnectionProvider module)
Example
%new-style
%enable-all-warnings
%requires WebSocketClient
*string url = shift ARGV;
if (!url) {
stderr.printf("usage: %s <URL>\n", get_script_name());
exit(1);
}
code callback = sub (*data d) {
if (d.typeCode() == NT_BINARY) {
printf("binary msg received: %y\n", d);
} else if (d) {
printf("%s\n", d);
}
};
WebSocketClient ws(callback, {"url": url});
ws.connect();
Counter c(1);
c.waitForZero();
WebSocketClient Module Release History
v2.1.1
- the data provider factory uses the delayed observable class instead (issue 4701)
v2.1
- fixed a deadlock deleting the client object when it goes out of scope in the event thread (issue 4697)
- added the
headers
option to allow auth headers to be set in WebSocket client connections and data providers (issue 4694)
v2.0
v1.9.1
- added support for continuation frames (issue 4073)
v1.9
- implemented support for a data provider scheme cache and rich option information for connections (issue 4025)
v1.8
- removed the
WebSocketConnectionObject::getConstructorInfo()
and WebSocketConnectionObject::getConstructorInfoImpl()
methods (issue 3696)
- added support for socket events (issue 3425)
v1.7
- all connection clases have unified constructor
- added the
WebSocketConnectionObject::getConstructorInfo()
method to allow connections to be created dynamically, potentially in another process from a network call (removed in WebSocketClient 1.8) (issue 2628)
- add WebSocketClient handling of WSCC_GoingAway event
v1.6.3
- added missing exception handling in the connection close callback (issue 3225)
v1.6.2
- allowed the handling of
PING
messages to be customized (issue 2887)
v1.6.1
- added WebSocketClient::pong() to allow an unsolicited
PONG
message to be sent as a unidirectional keep-alive message from the client to the server (issue 2566)
v1.6
- added the WebSocketConnectionObject class to support the ConnectionProvider module
- updated for complex types
- fixed a bug where the event loop thread would immediately terminate after a reconnection (issue 2061)
- improved client logging
- fixed a bug where the WebSocketClient::WebSocketClient class did not validate the
Sec-WebSocket-Accept
response header according to RFC6455 (issue 2062)
- added support for the
yield
option in the constructor
v1.5
v1.4
- fixed a bug parsing and generating the websocket close status code (issue 1216)
v1.3
- ignore
SOCKET-NOT-OPEN
errors when closing (server already closed the connection)
v1.2
- prepend
"WebSocketClient: "
to log messages
v1.1
- added socket instrumention support from Qore 0.8.9
v1.0
- the initial version of the WebSocketClient module