All Classes Namespaces Functions Variables Groups Pages
WebSocketClient.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* WebSocketClient.qm Copyright 2013 - 2017 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// minimum required Qore version
// require type definitions everywhere
// enable all warnings
namespace WebSocketClient {
const WsSchemes = (
"ws": (
"ssl": False,
),
"wss": (
"ssl": True,
),
);
const WsDefaultPort = 80;
class WebSocketClient {
public:
private :
Mutex m();
HTTPClient hc;
int stop = 0;
Counter c();
code callback;
*code log;
*code errlog;
*code debuglog;
timeout timeout_ms = DefaultTimeout;
int cid = -1;
*code yield;
static Sequence seq();
public:
public :
const DefaultTimeout = 15s;
const Version = "1.6";
const DefaultUserAgent = sprintf("Qore-WebSocketClient/%s", WebSocketClient::Version);
public:
constructor(code cb, hash opts);
destructor();
int getConnectionId();
hash getSchemes();
hash connect(*hash opts, *reference<hash> info);
bool isOpen();
disconnect(int cmd = WSCC_GoingAway);
nothing clearWarningQueue();
nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, auto arg, timeout min_ms = 1s);
hash getUsageInfo();
clearStats();
private:
disconnectUnlocked(int cmd = WSCC_GoingAway);
public:
private:
eventLoop(code callback);
public:
private:
logInfo(string fmt);
public:
private:
logError(string fmt);
public:
private:
logDebug(string fmt);
public:
private:
sendClose(int code, *string txtmsg);
public:
private:
hash connectUnlocked(*hash hdr, *reference<hash> info);
public:
pong();
send(string str);
send(binary bin);
};
class WebSocketConnectionObject : public ConnectionProvider::AbstractConnection {
public:
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
string getType();
*hash getRuntimeOptions();
private:
WebSocketClient getImpl(bool connect = True, *hash rtopts);
public:
hash getOptions();
*hash getDefaultOptions();
private:
hash<PingInfo> pingIntern(hash<PingInfo> rv);
public:
static WebSocketConnectionObject make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
};
};
WSCC_GoingAway
const WSCC_GoingAway
ConnectionProvider::AbstractConnection::monitor
bool monitor
WebSocketClient::WebSocketClient::connect
hash connect(*hash opts, *reference< hash > info)
connects to the websocket server
sprintf
string sprintf(string fmt,...)
WebSocketClient::WebSocketConnectionObject::getRuntimeOptions
*hash getRuntimeOptions()
returns runtime options
WebSocketClient::WebSocketClient::clearWarningQueue
nothing clearWarningQueue()
Removes any warning Queue object from the Socket.
WebSocketClient::WebSocketClient::clearStats
clearStats()
Clears performance statistics.
WebSocketClient::WsSchemes
const WsSchemes
known websocket schemes
Definition: WebSocketClient.qm.dox.h:109
ConnectionProvider::AbstractConnection::opts
*hash opts
True
const True
WebSocketClient::WebSocketClient::yield
*code yield
callable object to yield the current thread&#39;s execution
Definition: WebSocketClient.qm.dox.h:147
ConnectionProvider::AbstractConnection::name
string name
WebSocketClient::WebSocketClient::cid
int cid
unique websocket connection ID; -1 when not connected
Definition: WebSocketClient.qm.dox.h:145
WebSocketClient::WebSocketClient::getConnectionId
int getConnectionId()
returns the unique connection ID
binary
binary binary()
WebSocketClient::WebSocketClient::isOpen
bool isOpen()
returns True if the connection is currently open and active, False if not
WebSocketClient::WebSocketConnectionObject::constructor
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the WebSocketConnectionObject object
WebSocketClient::WsDefaultPort
const WsDefaultPort
default port for connections
Definition: WebSocketClient.qm.dox.h:119
ConnectionProvider::AbstractConnection::urlh
hash urlh
WebSocketClient::WebSocketClient::destructor
destructor()
disconnects the connection and stops the event thread if connected
False
const False
WebSocketClient::WebSocketClient
the main websocket client class
Definition: WebSocketClient.qm.dox.h:131
WebSocketClient::WebSocketClient::constructor
constructor(code cb, hash opts)
creates the object and optionally sets logging targets
WebSocketClient::WebSocketConnectionObject::getType
string getType()
returns &quot;websocket&quot;
ConnectionProvider::AbstractConnection
WebSocketClient::WebSocketConnectionObject
class for websocket connections; returns an object of class WebSocketClient for receiving websocket e...
Definition: WebSocketClient.qm.dox.h:405
WebSocketClient::WebSocketConnectionObject::make
static WebSocketConnectionObject make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
WebSocketClient::WebSocketClient::setWarningQueue
nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, auto arg, timeout min_ms=1s)
Sets a Queue object to receive socket warnings.
WebSocketClient::WebSocketClient::send
send(string str)
Sends string data over the web socket with timeout specified in options; if any errors occur...
WebSocketClient::WebSocketConnectionObject::getOptions
hash getOptions()
gets options
ConnectionProvider::AbstractConnection::desc
string desc
WebSocketClient::WebSocketClient::getSchemes
hash getSchemes()
returns a hash of URL scheme information for URL schemes supported by this object ...
WebSocketClient::WebSocketClient::pong
pong()
Sends a PONG message to the server as a unidirectional keep-alive message.
WebSocketClient::WebSocketClient::disconnect
disconnect(int cmd=WSCC_GoingAway)
disconnect with the given close code
WebSocketClient::WebSocketClient::DefaultUserAgent
const DefaultUserAgent
default user agent string for HTTP requests
Definition: WebSocketClient.qm.dox.h:161
WebSocketClient::WebSocketConnectionObject::getDefaultOptions
*hash getDefaultOptions()
returns default options
WebSocketClient::WebSocketClient::Version
const Version
module version
Definition: WebSocketClient.qm.dox.h:158
WebSocketClient::WebSocketClient::DefaultTimeout
const DefaultTimeout
default socket I/O operation timeout: 15 seconds
Definition: WebSocketClient.qm.dox.h:155
WebSocketClient::WebSocketConnectionObject::getImpl
WebSocketClient getImpl(bool connect=True, *hash rtopts)
returns a WebSocketClient object
ConnectionProvider::AbstractConnection::url
string url
hash
hash hash(object obj)
WebSocketClient::WebSocketClient::getUsageInfo
hash getUsageInfo()
Returns performance statistics for the socket.