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 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.8 or better
26 
27 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 
32 
33 /* Version History
34  * 2013-10-04 v1.0: David Nichols <david@qore.org>
35  + the initial version of the WebSocketClient module
36 */
37 
74 namespace WebSocketClient {
77  const WsSchemes = (
78  "ws": (
79  "ssl": False,
80  ),
81  "wss": (
82  "ssl": True,
83  ),
84  );
85 
87  const WsDefaultPort = 80;
88 
90 
97 
98 public:
99  private :
100  Mutex m();
101  HTTPClient hc();
102  int stop = 0;
103  Counter c();
104  code callback;
105  *code log;
106  *code errlog;
107  *code debuglog;
108  timeout timeout_ms = DefaultTimeout;
109 
110 public:
111 
112  public :
113  const DefaultTimeout = 15s;
114 
115  const Version = "1.0";
116 
117  const DefaultUserAgent = sprintf("Qore-WebSocketClient/%s", WebSocketClient::Version);
118 
119 public:
120 
122 
141  constructor(code callback, hash opts);
142 
143 
145 
171  hash connect(*hash opts, *reference info);
172 
173 
175  bool isOpen();
176 
177 
179  disconnect(int cmd = WSCC_GoingAway);
180 
181 
182 
183 private:
184  disconnectUnlocked(int cmd = WSCC_GoingAway);
185 public:
186 
187 
188 
189 private:
190  eventLoop(code callback);
191 public:
192 
193 
194 
195 private:
196  logInfo(string fmt);
197 public:
198 
199 
200 
201 private:
202  logError(string fmt);
203 public:
204 
205 
206 
207 private:
208  logDebug(string fmt);
209 public:
210 
211 
212 
213 private:
214  sendClose(int code, *string txtmsg);
215 public:
216 
217 
218 
219 private:
220  hash connectUnlocked(*hash hdr, *reference info);
221 public:
222 
223 
224  send(string str);
225 
226 
227  send(binary bin);
228 
229  };
230 };
const WSCC_GoingAway
string sprintf(string fmt,...)
const WsSchemes
known websocket schemes
Definition: WebSocketClient.qm.dox.h:77
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:87
const False
the main websocket client class
Definition: WebSocketClient.qm.dox.h:96
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 connect(*hash opts, *reference info)
connects to the websocket server