NAP
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
IWebSocketClientEndPoint Class Referenceabstract

#include <iwebsocketclientendpoint.h>

Public Member Functions

virtual bool send (const WebSocketConnection &connection, const std::string &message, EWebSocketOPCode code, nap::utility::ErrorState &error)=0
 
virtual bool send (const WebSocketConnection &connection, void const *payload, int length, EWebSocketOPCode code, nap::utility::ErrorState &error)=0
 
- Public Member Functions inherited from Device
virtual bool start (utility::ErrorState &errorState)
 
virtual void stop ()
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual bool init (utility::ErrorState &errorState)
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

bool mLogConnectionUpdates = true
 Property: "LogConnectionUpdates" if client / server connection information is logged to the console. More...
 
EWebSocketLogLevel mLibraryLogLevel = EWebSocketLogLevel::Warning
 Property: "LibraryLogLevel" library related equal to or higher than requested are logged. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Protected Member Functions

virtual bool registerClient (IWebSocketClient &client, utility::ErrorState &error)=0
 
virtual void unregisterClient (const IWebSocketClient &client)=0
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

Web socket client endpoint interface. Manages a list of client-server connections and acts as the main portal for the client to the server. Every web-socket client receives connection updates and messages from an endpoint. The endpoint is a device that can be started and stopped.

When stopped all active client-server connections are closed. This occurs when file changes are detected and the content of the application is hot-reloaded. Typically an application has only one endpoint. Multiple clients can reference the same endpoint. Every connection update and message is forwarded to the client from a background thread. To receive connection updates and messages a client must be dervied from nap::IWebSocketClient.

Note that depending on your operating system you might have to run the application as administrator to open a web-socket.

Inheritance diagram for IWebSocketClientEndPoint:
[legend]
Collaboration diagram for IWebSocketClientEndPoint:
[legend]

Member Function Documentation

◆ registerClient()

virtual bool registerClient ( IWebSocketClient client,
utility::ErrorState error 
)
protectedpure virtual

Connects a nap client to a server. The new connection is managed by this endpoint. The client is added to the list of internally managed clients.

Parameters
clientthe client to register
errorcontains the error is registration fails.
Returns
if the client was registered successfully

Implemented in WebSocketClientEndPointSetup< config >, and WebSocketClientEndPointSetup< wspp::ConfigTLS >.

◆ send() [1/2]

virtual bool send ( const WebSocketConnection connection,
const std::string &  message,
EWebSocketOPCode  code,
nap::utility::ErrorState error 
)
pure virtual

Sends a message to a server.

Parameters
connectionthe client connection to the server.
messagethe message to send.
codetype of message.
errorcontains the error if sending fails.
Returns
if message was sent successfully

Implemented in WebSocketClientEndPointSetup< config >, and WebSocketClientEndPointSetup< wspp::ConfigTLS >.

◆ send() [2/2]

virtual bool send ( const WebSocketConnection connection,
void const *  payload,
int  length,
EWebSocketOPCode  code,
nap::utility::ErrorState error 
)
pure virtual

Sends a message using the given payload and opcode to a server.

Parameters
connectionthe client connection to the server.
payloadthe message buffer.
lengthbuffer size in bytes.
codetype of message.
errorcontains the error if sending fails.
Returns
if message was sent successfully.

Implemented in WebSocketClientEndPointSetup< config >, and WebSocketClientEndPointSetup< wspp::ConfigTLS >.

◆ unregisterClient()

virtual void unregisterClient ( const IWebSocketClient client)
protectedpure virtual

Removes a client (resource) from the list of actively managed connection. If the client connection is currently open it will be closed. Asserts if the client isn't part of the system or can't be removed.

Parameters
clientthe client to remove.

Implemented in WebSocketClientEndPointSetup< config >, and WebSocketClientEndPointSetup< wspp::ConfigTLS >.

Member Data Documentation

◆ mLibraryLogLevel

Property: "LibraryLogLevel" library related equal to or higher than requested are logged.

◆ mLogConnectionUpdates

bool mLogConnectionUpdates = true

Property: "LogConnectionUpdates" if client / server connection information is logged to the console.