Qore WebSocketHandler Module Reference  1.4.2
WebSocketHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* WebSocketHandler.qm Copyright 2013 - 2018 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 // this module requires Qore 0.8.13 or better
26 
27 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 
32 
33 
78 namespace WebSocketHandler {
81 
90 
91 public:
92  public :
93  WebSocketHandler handler;
94 
95  // wait a maximum of 1/2 second for data
96  const DefaultQueuePollingInterval = 500ms;
97 
98 public:
99 
100  private :
103 
104 public:
105 
107  constructor(WebSocketHandler n_handler);
108 
109 
111  *binary pollData();
112 
113 
116 
117 
119  sendEncoded(binary msg);
120 
121 
123  send(data msg);
124 
125 
127 
129  gotMessage(string msg);
130 
131 
133 
135  gotMessage(binary msg);
136 
137 
139 
142 
143 
145 
148  registered();
149 
150  };
151 
153 
168 
169 public:
170  public :
172  const DefaultSocketSendTimeout = 30s;
173 
175  const DefaultHeartbeatInterval = 20s;
176 
178  const DefaultHeartbeatMsg = "heartbeat";
179 
181  const Options = (
182  "heartbeat",
183  "heartbeat_msg",
184  );
185 
186 public:
187 
188  private :
190  RWLock rwl();
191 
194 
196  softint heartbeat = DefaultHeartbeatInterval;
197 
199  string heartbeat_msg = DefaultHeartbeatMsg;
200 
201 public:
202 
204 
212 
213 
215 
219  int getHeartbeat();
220 
221 
223 
227  setHeartbeat(softint seconds);
228 
229 
231 
235  string getHeartbeatMessage();
236 
237 
239 
243  setHeartbeatMessage(string msg);
244 
245 
247 
271  hash handleRequest(hash cx, hash hdr, *data b);
272 
273 
275 
277  *list getConnectionIds();
278 
279 
281 
295  startImpl(softstring lid, hash cx, hash hdr, Qore::Socket sock);
296 
297 
299  WebSocketConnection getConnectionImpl(hash cx, hash hdr, string cid);
300 
301 
303  deregisterConnectionImpl(WebSocketConnection wsc);
304 
305 
307 
309  sendAll(data d);
310 
311 
313 
317  sendOne(softstring id, data d);
318 
319 
320 
321 private:
322  sendClose(Qore::Socket sock, int code, *string txtmsg);
323 public:
324 
325 
326  static string getDataString(*data data);
327 
329  logInfo(string fmt);
330 
331 
333  logError(string fmt);
334 
335 
337  logDebug(string fmt);
338 
339  };
340 };
*binary pollData()
this method is called by the WebSocketHandler to poll for messages from the client to send from the s...
this class represents a connection to a websocket client
Definition: WebSocketHandler.qm.dox.h:89
binary binary()
*binary pollDataImmediate()
this method is called by the WebSocketHandler to poll for messages from the client to send from the s...
list list(...)
connectionClosed()
this method is called by the WebSocketHandler when the connection is closed
the WebSocketHandler namespace contains all the objects in the WebSocketHandler module ...
Definition: WebSocketHandler.qm.dox.h:79
send(data msg)
pushes an unencoded message on the connection's message queue; the message will be encoded with WebSo...
hash ch
connection hash
Definition: WebSocketHandler.qm.dox.h:193
registered()
called when the connection has been registered in handler and accept sending messages (e...
gotMessage(string msg)
this method is called by the WebSocketHandler when messages from the client are received ...
date seconds(softint seconds)
hash hash(object obj)
Qore::Thread::Queue queue()
the Queue object stores messages to be sent to the server
constructor(WebSocketHandler n_handler)
the constructor is called by the WebSocketHandler when a new connection is made by a websocket client...
sendEncoded(binary msg)
pushes an already-encoded message on the connection's message queue