Support Forum G3D Web Page |
Subclass this if your websockets do not need to share state across all instances of a URI handler per-WebServer instance. More...
Inherits G3D::ReferenceCountedObject.
Public Types | |
enum | Opcode { TEXT = 0x1, BINARY = 0x2 } |
Public Member Functions | |
virtual void | onClose () |
Invoked on arbitrary threads. More... | |
virtual bool | onConnect () |
Return true to accept this connection. More... | |
virtual bool | onData (Opcode opcode, char *data, size_t data_len) |
Invoked when data appears. More... | |
virtual void | onReady () |
Invoked when both sides have accepted the connection. More... | |
virtual int | send (Opcode opcode, const uint8 *data, size_t dataLen) |
Returns the number of bytes written, 0 if the connection was closed, and -1 on error. More... | |
int | send (const String &s) |
Sends as TEXT. More... | |
int | send (const class BinaryOutput &b) |
Sends as BINARY. More... | |
Public Attributes | |
const NetAddress | clientAddress |
Protected Member Functions | |
WebSocket (WebServer *server, mg_connection *connection, const NetAddress &clientAddress) | |
Static Protected Member Functions | |
template<class T , class ... ArgTypes> | |
static shared_ptr< T > | createShared (ArgTypes &&... args) |
Like std::make_shared, but works for protected constructors. More... | |
Protected Attributes | |
struct mg_connection * | m_connection |
WebServer * | m_server |
Subclass this if your websockets do not need to share state across all instances of a URI handler per-WebServer instance.
If you do need to share data, subclass
|
inlineprotected |
|
inlinestaticprotectedinherited |
Like std::make_shared, but works for protected constructors.
Call as createShared<myclass>.
|
inlinevirtual |
Invoked on arbitrary threads.
|
inlinevirtual |
Return true to accept this connection.
Default implementation returns true. Invoked on arbitrary threads.
|
inlinevirtual |
Invoked when data appears.
Return true to maintain the connection.
Note that the Opcode may be values other than TEXT and BINARY, in which case programs should ignore the message and return true unless they have special ways of interacting at a low level with the WebSocket protocol.
Default returns true; Invoked on arbitrary threads.
|
inlinevirtual |
Invoked when both sides have accepted the connection.
Invoked on arbitrary threads.
|
virtual |
Returns the number of bytes written, 0 if the connection was closed, and -1 on error.
Referenced by send().
|
inline |
Sends as TEXT.
int G3D::WebServer::WebSocket::send | ( | const class BinaryOutput & | b | ) |
Sends as BINARY.
const NetAddress G3D::WebServer::WebSocket::clientAddress |
|
protected |
|
protected |