#include <websocketserver.h>
Public Member Functions | |
WebSocketServer (WebSocketService &service) | |
bool | send (const WebSocketConnection &connection, const WebSocketMessage &message, nap::utility::ErrorState &error) |
bool | send (const WebSocketConnection &connection, void const *payload, int length, EWebSocketOPCode code, nap::utility::ErrorState &error) |
bool | send (const WebSocketConnection &connection, const std::string &message, EWebSocketOPCode code, nap::utility::ErrorState &error) |
bool | broadcast (const WebSocketMessage &message, nap::utility::ErrorState &error) |
bool | broadcast (void const *payload, int length, EWebSocketOPCode code, nap::utility::ErrorState &error) |
![]() | |
IWebSocketServer (WebSocketService &service) | |
virtual bool | init (utility::ErrorState &errorState) override |
virtual void | onDestroy () override |
![]() | |
WebSocketInterface (WebSocketService &service) | |
virtual | ~WebSocketInterface () |
template<typename T > | |
T & | as () |
template<typename T > | |
const T & | as () const |
![]() | |
Resource () | |
![]() | |
Object () | |
virtual | ~Object () |
Object (Object &)=delete | |
Object & | operator= (const Object &)=delete |
Object (Object &&)=delete | |
Object & | operator= (Object &&)=delete |
Additional Inherited Members | |
![]() | |
static bool | isIDProperty (rtti::Instance &object, const rtti::Property &property) |
![]() | |
ResourcePtr< IWebSocketServerEndPoint > | mEndPoint |
Property: 'EndPoint' the server endpoint that manages all client connections. More... | |
![]() | |
std::string | mID |
Property: 'mID' unique name of the object. Used as an identifier by the system. More... | |
![]() | |
void | addEvent (WebSocketEventPtr newEvent) |
![]() | |
std::queue< WebSocketEventPtr > | mEvents |
std::mutex | mEventMutex |
WebSocketService * | mService = nullptr |
Default implementation of a web-socket server. Receives and responds to client messages over a web socket and can be used to send a reply. Implements the IWebSocketServer interface. The server converts raw messages and connection updates from a nap::WebSocketServerEndPoint into web-socket events that can be interpreted by the running application. Events are generated on a background thread and consumed on the main thread on update(). Use a nap::WebSocketComponent to receive and react to client web-socket events in your application.
WebSocketServer | ( | WebSocketService & | service | ) |
Constructor
service | the web-socket service that forwards events to the application. |
bool broadcast | ( | const WebSocketMessage & | message, |
nap::utility::ErrorState & | error | ||
) |
Broadcasts a message to all connected clients
message | the message to send |
error | contains the error if sending fails |
bool broadcast | ( | void const * | payload, |
int | length, | ||
EWebSocketOPCode | code, | ||
nap::utility::ErrorState & | error | ||
) |
Broadcasts a message to all connected clients
payload | the data to send |
length | payload byte size |
code | message type |
error | contains the error if sending fails |
bool send | ( | const WebSocketConnection & | connection, |
const std::string & | message, | ||
EWebSocketOPCode | code, | ||
nap::utility::ErrorState & | error | ||
) |
Sends a message with the given opcode to a client.
connection | the client connection |
message | the message to send |
code | message type |
error | contains the error if sending fails |
bool send | ( | const WebSocketConnection & | connection, |
const WebSocketMessage & | message, | ||
nap::utility::ErrorState & | error | ||
) |
Sends a message to a client.
connection | the client connection |
message | the message to send |
error | contains the error if sending fails |
bool send | ( | const WebSocketConnection & | connection, |
void const * | payload, | ||
int | length, | ||
EWebSocketOPCode | code, | ||
nap::utility::ErrorState & | error | ||
) |
Sends a message using the given payload and opcode to a client.
connection | the client connection |
payload | the message buffer |
length | total number of bytes |
code | message type |
error | contains the error if sending fails |