Loading...
Searching...
No Matches
SewioWebSocketClient::SewioWebSocketClient Class Reference

the main Sewio websocket client class More...

Inheritance diagram for SewioWebSocketClient::SewioWebSocketClient:
[legend]

## Public Member Functions

| constructor (code cb, hash opts)
| creates the object and optionally sets logging targets
hash | getSchemes ()
| returns a hash of URL scheme information for URL schemes supported by this object
| sendData (string method, string resource, *hash h)
| sends data to the server

## Public Attributes

const | DefaultUserAgent = sprintf("Qore-SewioWebSocketClient/%s", SewioWebSocketClient::Version)
| default user agent string for HTTP requests
const | RequiredOptions = ...
| required options
const | Version = "1.0"
| module version

## Protected Member Functions

hash | connectUnlocked (*hash hdr, *reference< hash > info)
| connects to the target server and starts the event listener thread

## Static Protected Member Functions

static code | getCallback (code cb)
| extern callback wrapper to parse the JSON and call the user's callback with the deserialized data

## Detailed Description

the main Sewio websocket client class

To use this class, create a SewioWebSocketClient object and the call WebSocketClient::connect().

The WebSocketClient::connect() method starts a background thread to receive messages, which are then posted to the callback provided in the SewioWebSocketClient::constructor() method call.

To stop listening for web socket events, call WebSocketClient::disconnect().

To send data to the Sewio RTLS Studio server, use the SewioWebSocketClient::send() method; this method will serialize the data to JSON and send the JSON string to the server.

When websocket messages are received from the server, they are deserialized and the resulting data is used as the argument to the callback closure mentioned above.

## Member Function Documentation

## constructor()

SewioWebSocketClient::SewioWebSocketClient::constructor | ( | code | cb,
|  | hash | opts
| ) |  |

creates the object and optionally sets logging targets

Example:
  sub event(*data msg) {
  if (!msg)
  printf("connection closed\n");
  else
  printf("%s msg: %y\n", now_us().format("YYYY-MM-DD HH:mm:SS.xx"), msg);
  }
  SewioWebSocketClient ws(\event(), ("url": "ws://example.com:8080/path"));

Parameters

  cb | the callback closure or call reference for received messages; this callback must accept a *hash argument as it will only be called with deserialized data until the connection is closed, at which time it will be called with NOTHING

  opts

  an option hash for the HTTPClient constructor plus the following keys:
  - `apikey:` (required) a string giving the Sewio RTLS Studio API key
  - `log:` (optional) closure or call reference for informational logging
  - `errlog:` (optional) closure or call reference for error logging
  - `debuglog:` (optional) closure or call reference for logging debugging/technical messages about the web socket connection

Exceptions

  SEWIOWEBSOCKETCLIENT-ERROR | unknown scheme, missing or invalid 'url' or 'apikey' key in option hash