Qore WebSocketClient Module Reference  1.4
 All Classes Namespaces Functions Variables Groups Pages
WebSocketClient.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* WebSocketClient.qm Copyright 2013 - 2016 Qore Technologies, s.r.o.
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // minimum required Qore version
26 
27 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 
32 
33 
91 namespace WebSocketClient {
94  const WsSchemes = (
95  "ws": (
96  "ssl": False,
97  ),
98  "wss": (
99  "ssl": True,
100  ),
101  );
102 
104  const WsDefaultPort = 80;
105 
107 
114 
115 public:
116  private :
117  Mutex m();
118  HTTPClient hc();
119  int stop = 0;
120  Counter c();
121  code callback;
122  *code log;
123  *code errlog;
124  *code debuglog;
125  timeout timeout_ms = DefaultTimeout;
126 
127 public:
128 
129  public :
130  const DefaultTimeout = 15s;
131 
132  const Version = "1.0";
133 
134  const DefaultUserAgent = sprintf("Qore-WebSocketClient/%s", WebSocketClient::Version);
135 
136 public:
137 
139 
158  constructor(code cb, hash opts);
159 
160 
162 
188  hash connect(*hash opts, *reference info);
189 
190 
192  bool isOpen();
193 
194 
196  disconnect(int cmd = WSCC_GoingAway);
197 
198 
200 
209  nothing clearWarningQueue();
210 
211 
213 
243  nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, any arg, timeout min_ms = 1s);
244 
245 
247 
265  hash getUsageInfo();
266 
267 
269 
278  clearStats();
279 
280 
281  private disconnectUnlocked(int cmd = WSCC_GoingAway);
282 
283 
284  private eventLoop(code callback);
285 
286 
287  private logInfo(string fmt);
288 
289 
290  private logError(string fmt);
291 
292 
293  private logDebug(string fmt);
294 
295 
296  private sendClose(int code, *string txtmsg);
297 
298 
299  private hash connectUnlocked(*hash hdr, *reference info);
300 
301 
302  send(string str);
303 
304 
305  send(binary bin);
306 
307  };
308 };
const WSCC_GoingAway
string sprintf(string fmt,...)
nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, any arg, timeout min_ms=1s)
Sets a Queue object to receive socket warnings.
nothing clearWarningQueue()
Removes any warning Queue object from the Socket.
clearStats()
Clears performance statistics.
const WsSchemes
known websocket schemes
Definition: WebSocketClient.qm.dox.h:94
const True
binary binary()
bool isOpen()
returns True if the connection is currently open and active, False if not
const WsDefaultPort
default port for connections
Definition: WebSocketClient.qm.dox.h:104
const False
the main websocket client class
Definition: WebSocketClient.qm.dox.h:113
constructor(code cb, hash opts)
creates the object and optionally sets logging targets
disconnect(int cmd=WSCC_GoingAway)
disconnect with the given close code
hash hash(object obj)
hash getUsageInfo()
Returns performance statistics for the socket.
hash connect(*hash opts, *reference info)
connects to the websocket server