CppServer  1.0.4.0
C++ Server Library
Public Member Functions | Protected Member Functions | List of all members
CppServer::WS::WSSServer Class Reference

WebSocket secure server. More...

#include <wss_server.h>

Inheritance diagram for CppServer::WS::WSSServer:
CppServer::HTTP::HTTPSServer CppServer::WS::WebSocket CppServer::Asio::SSLServer

Public Member Functions

 WSSServer (const WSSServer &)=delete
 
 WSSServer (WSSServer &&)=delete
 
virtual ~WSSServer ()=default
 
WSSServeroperator= (const WSSServer &)=delete
 
WSSServeroperator= (WSSServer &&)=delete
 
virtual bool CloseAll ()
 
virtual bool CloseAll (int status)
 
virtual bool CloseAll (int status, const void *buffer, size_t size)
 
virtual bool CloseAll (int status, std::string_view text)
 
bool Multicast (const void *buffer, size_t size) override
 Multicast data to all connected WebSocket sessions. More...
 
size_t MulticastText (const void *buffer, size_t size)
 
size_t MulticastText (std::string_view text)
 
size_t MulticastBinary (const void *buffer, size_t size)
 
size_t MulticastBinary (std::string_view text)
 
size_t MulticastPing (const void *buffer, size_t size)
 
size_t MulticastPing (std::string_view text)
 
- Public Member Functions inherited from CppServer::HTTP::HTTPSServer
 HTTPSServer (const HTTPSServer &)=delete
 
 HTTPSServer (HTTPSServer &&)=delete
 
virtual ~HTTPSServer ()=default
 
HTTPSServeroperator= (const HTTPSServer &)=delete
 
HTTPSServeroperator= (HTTPSServer &&)=delete
 
CppCommon::FileCache & cache () noexcept
 Get the static content cache. More...
 
const CppCommon::FileCache & cache () const noexcept
 
void AddStaticContent (const CppCommon::Path &path, const std::string &prefix="/", const CppCommon::Timespan &timeout=CppCommon::Timespan::hours(1))
 Add static content cache. More...
 
void RemoveStaticContent (const CppCommon::Path &path)
 Remove static content cache. More...
 
void ClearStaticContent ()
 Clear static content cache. More...
 
void Watchdog (const CppCommon::UtcTimestamp &utc=CppCommon::UtcTimestamp())
 Watchdog the static content cache. More...
 
- Public Member Functions inherited from CppServer::Asio::SSLServer
 SSLServer (const std::shared_ptr< Service > &service, const std::shared_ptr< SSLContext > &context, int port, InternetProtocol protocol=InternetProtocol::IPv4)
 Initialize SSL server with a given Asio service, SSL context and port number. More...
 
 SSLServer (const std::shared_ptr< Service > &service, const std::shared_ptr< SSLContext > &context, const std::string &address, int port)
 Initialize SSL server with a given Asio service, SSL context, server address and port number. More...
 
 SSLServer (const std::shared_ptr< Service > &service, const std::shared_ptr< SSLContext > &context, const asio::ip::tcp::endpoint &endpoint)
 Initialize SSL server with a given a given Asio service, SSL context and endpoint. More...
 
 SSLServer (const SSLServer &)=delete
 
 SSLServer (SSLServer &&)=delete
 
virtual ~SSLServer ()=default
 
SSLServeroperator= (const SSLServer &)=delete
 
SSLServeroperator= (SSLServer &&)=delete
 
const CppCommon::UUID & id () const noexcept
 Get the server Id. More...
 
std::shared_ptr< Service > & service () noexcept
 Get the Asio service. More...
 
std::shared_ptr< asio::io_service > & io_service () noexcept
 Get the Asio IO service. More...
 
asio::io_service::strand & strand () noexcept
 Get the Asio service strand for serialized handler execution. More...
 
std::shared_ptr< SSLContext > & context () noexcept
 Get the server SSL context. More...
 
asio::ip::tcp::endpoint & endpoint () noexcept
 Get the server endpoint. More...
 
asio::ip::tcp::acceptor & acceptor () noexcept
 Get the server acceptor. More...
 
const std::string & address () const noexcept
 Get the server address. More...
 
int port () const noexcept
 Get the server port number. More...
 
uint64_t connected_sessions () const noexcept
 Get the number of sessions connected to the server. More...
 
uint64_t bytes_pending () const noexcept
 Get the number of bytes pending sent by the server. More...
 
uint64_t bytes_sent () const noexcept
 Get the number of bytes sent by the server. More...
 
uint64_t bytes_received () const noexcept
 Get the number of bytes received by the server. More...
 
bool option_keep_alive () const noexcept
 Get the option: keep alive. More...
 
bool option_no_delay () const noexcept
 Get the option: no delay. More...
 
bool option_reuse_address () const noexcept
 Get the option: reuse address. More...
 
bool option_reuse_port () const noexcept
 Get the option: reuse port. More...
 
bool IsStarted () const noexcept
 Is the server started? More...
 
virtual bool Start ()
 Start the server. More...
 
virtual bool Stop ()
 Stop the server. More...
 
virtual bool Restart ()
 Restart the server. More...
 
virtual bool Multicast (std::string_view text)
 Multicast text to all connected sessions. More...
 
virtual bool DisconnectAll ()
 Disconnect all connected sessions. More...
 
std::shared_ptr< SSLSessionFindSession (const CppCommon::UUID &id)
 Find a session with a given Id. More...
 
void SetupKeepAlive (bool enable) noexcept
 Setup option: keep alive. More...
 
void SetupNoDelay (bool enable) noexcept
 Setup option: no delay. More...
 
void SetupReuseAddress (bool enable) noexcept
 Setup option: reuse address. More...
 
void SetupReusePort (bool enable) noexcept
 Setup option: reuse port. More...
 

Protected Member Functions

std::shared_ptr< Asio::SSLSessionCreateSession (const std::shared_ptr< Asio::SSLServer > &server) override
 
- Protected Member Functions inherited from CppServer::HTTP::HTTPSServer
std::shared_ptr< Asio::SSLSessionCreateSession (const std::shared_ptr< Asio::SSLServer > &server) override
 
- Protected Member Functions inherited from CppServer::Asio::SSLServer
virtual std::shared_ptr< SSLSessionCreateSession (const std::shared_ptr< SSLServer > &server)
 Create SSL session factory method. More...
 
virtual void onStarted ()
 Handle server started notification. More...
 
virtual void onStopped ()
 Handle server stopped notification. More...
 
virtual void onConnected (std::shared_ptr< SSLSession > &session)
 Handle session connected notification. More...
 
virtual void onHandshaked (std::shared_ptr< SSLSession > &session)
 Handle session handshaked notification. More...
 
virtual void onDisconnected (std::shared_ptr< SSLSession > &session)
 Handle session disconnected notification. More...
 
virtual void onError (int error, const std::string &category, const std::string &message)
 Handle error notification. More...
 
- Protected Member Functions inherited from CppServer::WS::WebSocket
virtual void onWSConnecting (HTTP::HTTPRequest &request)
 Handle WebSocket client connecting notification. More...
 
virtual void onWSConnected (const HTTP::HTTPResponse &response)
 Handle WebSocket client connected notification. More...
 
virtual bool onWSConnecting (const HTTP::HTTPRequest &request, HTTP::HTTPResponse &response)
 Handle WebSocket server session validating notification. More...
 
virtual void onWSConnected (const HTTP::HTTPRequest &request)
 Handle WebSocket server session connected notification. More...
 
virtual void onWSDisconnected ()
 Handle WebSocket client disconnected notification. More...
 
virtual void onWSReceived (const void *buffer, size_t size)
 Handle WebSocket received notification. More...
 
virtual void onWSClose (const void *buffer, size_t size, int status=1000)
 Handle WebSocket client close notification. More...
 
virtual void onWSPing (const void *buffer, size_t size)
 Handle WebSocket ping notification. More...
 
virtual void onWSPong (const void *buffer, size_t size)
 Handle WebSocket pong notification. More...
 
virtual void onWSError (const std::string &message)
 Handle WebSocket error notification. More...
 
virtual void SendResponse (const HTTP::HTTPResponse &response)
 Send WebSocket server upgrade response. More...
 
 WebSocket ()
 
 WebSocket (const WebSocket &)=delete
 
 WebSocket (WebSocket &&)=delete
 
 ~WebSocket ()=default
 
WebSocketoperator= (const WebSocket &)=delete
 
WebSocketoperator= (WebSocket &&)=delete
 
std::string_view ws_nonce () const noexcept
 Get the WebSocket random nonce. More...
 
bool PerformClientUpgrade (const HTTP::HTTPResponse &response, const CppCommon::UUID &id)
 Perform WebSocket client upgrade. More...
 
bool PerformServerUpgrade (const HTTP::HTTPRequest &request, HTTP::HTTPResponse &response)
 Perform WebSocket server upgrade. More...
 
void PrepareSendFrame (uint8_t opcode, bool mask, const void *buffer, size_t size, int status=0)
 Prepare WebSocket send frame. More...
 
void PrepareReceiveFrame (const void *buffer, size_t size)
 Prepare WebSocket receive frame. More...
 
size_t RequiredReceiveFrameSize ()
 Required WebSocket receive frame size. More...
 
void ClearWSBuffers ()
 Clear WebSocket send/receive buffers. More...
 
void InitWSNonce ()
 Initialize WebSocket random nonce. More...
 

Additional Inherited Members

- Protected Attributes inherited from CppServer::Asio::SSLServer
std::shared_mutex _sessions_lock
 
std::map< CppCommon::UUID, std::shared_ptr< SSLSession > > _sessions
 
- Protected Attributes inherited from CppServer::WS::WebSocket
bool _ws_handshaked {false}
 Handshaked flag. More...
 
uint8_t _ws_opcode
 Received frame opcode. More...
 
bool _ws_frame_received {false}
 Received frame flag. More...
 
bool _ws_final_received {false}
 Received final flag. More...
 
size_t _ws_header_size {0}
 Received frame header size. More...
 
size_t _ws_payload_size {0}
 Received frame payload size. More...
 
std::vector< uint8_t > _ws_receive_frame_buffer
 Receive frame buffer. More...
 
std::vector< uint8_t > _ws_receive_final_buffer
 Receive final buffer. More...
 
uint8_t _ws_receive_mask [4]
 Receive mask. More...
 
std::mutex _ws_send_lock
 Send buffer lock. More...
 
std::vector< uint8_t > _ws_send_buffer
 Send buffer. More...
 
uint8_t _ws_send_mask [4]
 Send mask. More...
 
std::array< uint8_t, 16 > _ws_nonce
 WebSocket random nonce of 16 bytes. More...
 
- Static Protected Attributes inherited from CppServer::WS::WebSocket
static const uint8_t WS_FIN = 0x80
 Final frame. More...
 
static const uint8_t WS_TEXT = 0x01
 Text frame. More...
 
static const uint8_t WS_BINARY = 0x02
 Binary frame. More...
 
static const uint8_t WS_CLOSE = 0x08
 Close frame. More...
 
static const uint8_t WS_PING = 0x09
 Ping frame. More...
 
static const uint8_t WS_PONG = 0x0A
 Pong frame. More...
 

Detailed Description

WebSocket secure server.

WebSocket secure server is used to communicate with clients using WebSocket secure protocol.

https://en.wikipedia.org/wiki/WebSocket

Thread-safe.

Examples
wss_chat_server.cpp.

Definition at line 28 of file wss_server.h.

Constructor & Destructor Documentation

◆ WSSServer() [1/2]

CppServer::WS::WSSServer::WSSServer ( const WSSServer )
delete

◆ WSSServer() [2/2]

CppServer::WS::WSSServer::WSSServer ( WSSServer &&  )
delete

◆ ~WSSServer()

virtual CppServer::WS::WSSServer::~WSSServer ( )
virtualdefault

Member Function Documentation

◆ CloseAll() [1/4]

virtual bool CppServer::WS::WSSServer::CloseAll ( )
inlinevirtual

Definition at line 41 of file wss_server.h.

◆ CloseAll() [2/4]

virtual bool CppServer::WS::WSSServer::CloseAll ( int  status)
inlinevirtual

Definition at line 42 of file wss_server.h.

◆ CloseAll() [3/4]

bool CppServer::WS::WSSServer::CloseAll ( int  status,
const void *  buffer,
size_t  size 
)
virtual

Definition at line 14 of file wss_server.cpp.

◆ CloseAll() [4/4]

bool CppServer::WS::WSSServer::CloseAll ( int  status,
std::string_view  text 
)
virtual

Definition at line 25 of file wss_server.cpp.

◆ CreateSession()

std::shared_ptr<Asio::SSLSession> CppServer::WS::WSSServer::CreateSession ( const std::shared_ptr< Asio::SSLServer > &  server)
inlineoverrideprotected
Examples
wss_chat_server.cpp.

Definition at line 62 of file wss_server.h.

◆ Multicast()

bool CppServer::WS::WSSServer::Multicast ( const void *  buffer,
size_t  size 
)
overridevirtual

Multicast data to all connected WebSocket sessions.

Reimplemented from CppServer::Asio::SSLServer.

Definition at line 36 of file wss_server.cpp.

◆ MulticastBinary() [1/2]

size_t CppServer::WS::WSSServer::MulticastBinary ( const void *  buffer,
size_t  size 
)
inline

Definition at line 54 of file wss_server.h.

◆ MulticastBinary() [2/2]

size_t CppServer::WS::WSSServer::MulticastBinary ( std::string_view  text)
inline

Definition at line 55 of file wss_server.h.

◆ MulticastPing() [1/2]

size_t CppServer::WS::WSSServer::MulticastPing ( const void *  buffer,
size_t  size 
)
inline

Definition at line 58 of file wss_server.h.

◆ MulticastPing() [2/2]

size_t CppServer::WS::WSSServer::MulticastPing ( std::string_view  text)
inline

Definition at line 59 of file wss_server.h.

◆ MulticastText() [1/2]

size_t CppServer::WS::WSSServer::MulticastText ( const void *  buffer,
size_t  size 
)
inline

Definition at line 50 of file wss_server.h.

◆ MulticastText() [2/2]

size_t CppServer::WS::WSSServer::MulticastText ( std::string_view  text)
inline

Definition at line 51 of file wss_server.h.

◆ operator=() [1/2]

WSSServer& CppServer::WS::WSSServer::operator= ( const WSSServer )
delete

◆ operator=() [2/2]

WSSServer& CppServer::WS::WSSServer::operator= ( WSSServer &&  )
delete

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