Qore WebSocketHandler Module Reference  1.4.1
 All Classes Namespaces Functions Variables Groups Pages
WebSocketHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* WebSocketHandler.qm Copyright 2013 - 2017 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 
74 namespace WebSocketHandler {
77 
86 
87 public:
88  public :
89  WebSocketHandler handler;
90 
91  // wait a maximum of 1/2 second for data
92  const DefaultQueuePollingInterval = 500ms;
93 
94 public:
95 
96  private :
99 
100 public:
101 
103  constructor(WebSocketHandler n_handler);
104 
105 
107  *binary pollData();
108 
109 
112 
113 
115  sendEncoded(binary msg);
116 
117 
119  send(data msg);
120 
121 
123 
125  gotMessage(string msg);
126 
127 
129 
131  gotMessage(binary msg);
132 
133 
135 
138 
139 
141 
144  registered();
145 
146  };
147 
149 
164 
165 public:
166  public :
167  // default socket send timeout
168  const DefaultSocketSendTimeout = 30s;
169 
170 public:
171 
172  private :
174  RWLock rwl();
175 
178 
179 public:
180 
182 
185 
186 
188 
212  hash handleRequest(hash cx, hash hdr, *data b);
213 
214 
216 
219 
220 
222 
236  startImpl(softstring lid, hash cx, hash hdr, Qore::Socket sock);
237 
238 
240  WebSocketConnection getConnectionImpl(hash cx, hash hdr, string cid);
241 
242 
245 
246 
248 
250  sendAll(data d);
251 
252 
254 
258  sendOne(softstring id, data d);
259 
260 
261 
262 private:
263  sendClose(Qore::Socket sock, int code, *string txtmsg);
264 public:
265 
266 
267  static string getDataString(*data data);
268 
270  logInfo(string fmt);
271 
272 
274  logError(string fmt);
275 
276 
278  logDebug(string fmt);
279 
280  };
281 };
*binary pollData()
this method is called by the WebSocketHandler to poll for messages from the client to send from the s...
logDebug(string fmt)
default implementation is empty
this class represents a connection to a websocket client
Definition: WebSocketHandler.qm.dox.h:85
binary binary()
*binary pollDataImmediate()
this method is called by the WebSocketHandler to poll for messages from the client to send from the s...
*list getConnectionIds()
get list of socket connection ids
hash handleRequest(hash cx, hash hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
list list(...)
deregisterConnectionImpl(WebSocketConnection wsc)
called when the connection terminates; the default implementation does nothing
WebSocketConnection getConnectionImpl(hash cx, hash hdr, string cid)
called when a connection is established; the default implementation creates a WebSocketConnection obj...
startImpl(softstring lid, hash cx, hash hdr, Qore::Socket sock)
called from the HTTP server after the handleRequest() method indicates that a dedicated connection sh...
sendAll(data d)
sends a message to all connected clients
sendOne(softstring id, data d)
sends a message to the given connection ID
connectionClosed()
this method is called by the WebSocketHandler when the connection is closed
the main web socket handler class
Definition: WebSocketHandler.qm.dox.h:163
logError(string fmt)
default implementation is empty
send(data msg)
pushes an unencoded message on the connection's message queue; the message will be encoded with WebSo...
RWLock rwl()
connection read-write lock
hash ch
connection hash
Definition: WebSocketHandler.qm.dox.h:177
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 ...
constructor(*HttpServer::AbstractAuthenticator auth)
create the object optionally with the given AbstractAuthenticator
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...
logInfo(string fmt)
default implementation is empty
sendEncoded(binary msg)
pushes an already-encoded message on the connection's message queue