Doxygen with github
Loading...
Searching...
No Matches
ksf::misc::ksWSServer Class Reference

A WebSocket server with authentication and text message handling. More...

#include <ksWSServer.h>

Classes

class  Impl
 

Public Member Functions

 ksWSServer (uint16_t port)
 Prepares ksWSServer on specified port without actually starting it.
 
virtual ~ksWSServer ()
 Destructs the server, releasing the resources.
 
uint64_t getRequiredAuthToken () const
 Returns simple authentication token for WebSocket authentication process.
 
void setRequiredAuthToken (uint64_t authToken)
 Sets simple authtoken for WebSocket authentication.
 
void begin ()
 Starts the server.
 
void loop ()
 Handles WebSocket server logic.
 
void setMessageHandler (ksWsServerMessageFunc_t func)
 Installs a message handler to receive WebSocket text messages.
 
bool sendTXT (uint8_t client, const char *payload, std::size_t length=0)
 Sends a text message to one client. A zero length uses a null-terminated payload.
 
bool broadcastTXT (const char *payload, std::size_t length=0)
 Sends a text message to all clients. A zero length uses a null-terminated payload.
 
void enableHeartbeat (uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount)
 Configures heartbeat intervals in milliseconds and the missed-pong limit.
 

Detailed Description

A WebSocket server with authentication and text message handling.

Constructor & Destructor Documentation

◆ ksWSServer()

ksf::misc::ksWSServer::ksWSServer ( uint16_t port)

Prepares ksWSServer on specified port without actually starting it.

Parameters
portPort to listen for incoming WebSocket connections.

Member Function Documentation

◆ getRequiredAuthToken()

uint64_t ksf::misc::ksWSServer::getRequiredAuthToken ( ) const

Returns simple authentication token for WebSocket authentication process.

The value 0 is considered to be empty token. Authentication token is set via setRequiredAuthToken().

Generally, this token should be generated earlier, then the WebServer should use Cookie to transmit it to the browser and then the browser should pass it with WebSocket requests (via HTTP Cookie header).

Returns
Auth token for WebSocket

◆ setMessageHandler()

void ksf::misc::ksWSServer::setMessageHandler ( ksWsServerMessageFunc_t func)

Installs a message handler to receive WebSocket text messages.

Parameters
funcThe message handler function.

◆ setRequiredAuthToken()

void ksf::misc::ksWSServer::setRequiredAuthToken ( uint64_t authToken)

Sets simple authtoken for WebSocket authentication.

The value 0 is considered to be invalid (no auth token). Auth token is set via setRequiredAuthToken(). Generally, this token should be generated earlier, then the WebServer should use Cookie to transmit it to the browser and then the browser should pass it with WebSocket requests (via HTTP Cookie header).

Parameters
authTokenThe token to set.

The documentation for this class was generated from the following files: