Qore WebSocketHandler Module Reference  1.0
 All Classes Namespaces Functions Variables Groups Pages
WebSocketHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* WebSocketHandler.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 WebSocketHandler module
36 */
37 
52 namespace WebSocketHandler {
55 
64 
65 public:
66  public :
67  WebSocketHandler handler;
68 
69  const DefaultQueuePollingInterval = 50ms;
70 
71 public:
72 
73  private :
76 
77 public:
78 
81 
82 
84  *binary pollData();
85 
86 
89 
90 
92  sendEncoded(binary msg);
93 
94 
96  send(data msg);
97 
98 
100  gotMessage(string msg);
101 
102 
104  gotMessage(binary msg);
105 
106  };
107 
109 
124 
125 public:
126  public :
127 
128 public:
129 
130  private :
132  RWLock rwl();
133 
136 
137 public:
138 
140 
143 
144 
146 
170  hash handleRequest(hash cx, hash hdr, *data b);
171 
172 
174 
188  startImpl(softstring lid, hash cx, hash hdr, Qore::Socket sock);
189 
190 
192  WebSocketConnection getConnectionImpl(hash cx, hash hdr, string cid);
193 
194 
197 
198 
200 
202  sendAll(data d);
203 
204 
206 
210  sendOne(string id, data d);
211 
212 
213 
214 private:
215  sendClose(Qore::Socket sock, int code, *string txtmsg);
216 public:
217 
218 
219  static string getDataString(*data data);
220 
222  logInfo(string fmt);
223 
224 
226  logError(string fmt);
227 
228 
230  logDebug(string fmt);
231 
232  };
233 };
*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:63
binary binary()
*binary pollDataImmediate()
this method is called by the WebSocketHandler to poll for messages from the client to send from the s...
hash handleRequest(hash cx, hash hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
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
the main web socket handler class
Definition: WebSocketHandler.qm.dox.h:123
logError(string fmt)
default implementation is empty
constructor(WebSocketHandler handler)
the constructor is called by the WebSocketHandler when a new connection is made by a websocket client...
send(data msg)
pushes an unencoded message on the connection&#39;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:135
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
sendOne(string id, data d)
sends a message to the given connection ID
hash hash(object obj)
Qore::Thread::Queue queue()
the Queue object stored messages to be sent to the server
logInfo(string fmt)
default implementation is empty
sendEncoded(binary msg)
pushes an already-encoded message on the connection&#39;s message queue