Qore WebSocketClient Module Reference  1.0
 All Classes Namespaces Functions Variables Groups Pages
WebSocketClient.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* WebSocketClient.qm Copyright 2013 - 2014 Qore Technologies, sro
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 // this module requires Qore 0.8.9 or better
26 
27 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 
32 
33 /* Version History
34  * 2014-02-04 v1.1: David Nichols <david@qore.org>
35  + added socket instrumention support from Qore 0.8.9
36 
37  * 2013-10-04 v1.0: David Nichols <david@qore.org>
38  + the initial version of the WebSocketClient module
39 */
40 
79 namespace WebSocketClient {
82  const WsSchemes = (
83  "ws": (
84  "ssl": False,
85  ),
86  "wss": (
87  "ssl": True,
88  ),
89  );
90 
92  const WsDefaultPort = 80;
93 
95 
102 
103 public:
104  private :
105  Mutex m();
106  HTTPClient hc();
107  int stop = 0;
108  Counter c();
109  code callback;
110  *code log;
111  *code errlog;
112  *code debuglog;
113  timeout timeout_ms = DefaultTimeout;
114 
115 public:
116 
117  public :
118  const DefaultTimeout = 15s;
119 
120  const Version = "1.0";
121 
122  const DefaultUserAgent = sprintf("Qore-WebSocketClient/%s", WebSocketClient::Version);
123 
124 public:
125 
127 
146  constructor(code callback, hash opts);
147 
148 
150 
176  hash connect(*hash opts, *reference info);
177 
178 
180  bool isOpen();
181 
182 
184  disconnect(int cmd = WSCC_GoingAway);
185 
186 
188 
197  nothing clearWarningQueue();
198 
199 
201 
231  nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, any arg, timeout min_ms = 1s);
232 
233 
235 
253  hash getUsageInfo();
254 
255 
257 
266  clearStats();
267 
268 
269  private disconnectUnlocked(int cmd = WSCC_GoingAway);
270 
271 
272  private eventLoop(code callback);
273 
274 
275  private logInfo(string fmt);
276 
277 
278  private logError(string fmt);
279 
280 
281  private logDebug(string fmt);
282 
283 
284  private sendClose(int code, *string txtmsg);
285 
286 
287  private hash connectUnlocked(*hash hdr, *reference info);
288 
289 
290  send(string str);
291 
292 
293  send(binary bin);
294 
295  };
296 };
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:82
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:92
const False
the main websocket client class
Definition: WebSocketClient.qm.dox.h:101
constructor(code callback, 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