Support Forum       G3D Web Page     
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
G3D::WebServer::WebSocket Class Reference

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
 
WebServerm_server
 

Detailed Description

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

Member Enumeration Documentation

◆ Opcode

Enumerator
TEXT 
BINARY 

Constructor & Destructor Documentation

◆ WebSocket()

G3D::WebServer::WebSocket::WebSocket ( WebServer server,
mg_connection *  connection,
const NetAddress clientAddress 
)
inlineprotected

Member Function Documentation

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ onClose()

virtual void G3D::WebServer::WebSocket::onClose ( )
inlinevirtual

Invoked on arbitrary threads.

◆ onConnect()

virtual bool G3D::WebServer::WebSocket::onConnect ( )
inlinevirtual

Return true to accept this connection.

Default implementation returns true. Invoked on arbitrary threads.

◆ onData()

virtual bool G3D::WebServer::WebSocket::onData ( Opcode  opcode,
char *  data,
size_t  data_len 
)
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.

◆ onReady()

virtual void G3D::WebServer::WebSocket::onReady ( )
inlinevirtual

Invoked when both sides have accepted the connection.

Invoked on arbitrary threads.

◆ send() [1/3]

virtual int G3D::WebServer::WebSocket::send ( Opcode  opcode,
const uint8 data,
size_t  dataLen 
)
virtual

Returns the number of bytes written, 0 if the connection was closed, and -1 on error.

Referenced by send().

◆ send() [2/3]

int G3D::WebServer::WebSocket::send ( const String s)
inline

Sends as TEXT.

◆ send() [3/3]

int G3D::WebServer::WebSocket::send ( const class BinaryOutput b)

Sends as BINARY.

Member Data Documentation

◆ clientAddress

const NetAddress G3D::WebServer::WebSocket::clientAddress

◆ m_connection

struct mg_connection* G3D::WebServer::WebSocket::m_connection
protected

◆ m_server

WebServer* G3D::WebServer::WebSocket::m_server
protected

documentation generated on Wed Nov 24 2021 08:02:02 using doxygen 1.8.15