CppServer  1.0.0.0
C++ Server Library
Public Member Functions | Protected Member Functions | List of all members
CppServer::Asio::WebSocketSSLClient Class Reference

WebSocket SSL client. More...

#include <websocket_ssl_client.h>

Inheritance diagram for CppServer::Asio::WebSocketSSLClient:

Public Member Functions

 WebSocketSSLClient (std::shared_ptr< Service > service, std::shared_ptr< asio::ssl::context > context, const std::string &uri)
 Initialize WebSocket client with a given Asio service, SSL context and server URI address. More...
 
 WebSocketSSLClient (const WebSocketSSLClient &)=delete
 
 WebSocketSSLClient (WebSocketSSLClient &&)=default
 
virtual ~WebSocketSSLClient ()=default
 
WebSocketSSLClientoperator= (const WebSocketSSLClient &)=delete
 
WebSocketSSLClientoperator= (WebSocketSSLClient &&)=default
 
const CppCommon::UUID & id () const noexcept
 Get the client Id. More...
 
std::shared_ptr< Service > & service () noexcept
 Get the Asio service. More...
 
std::shared_ptr< asio::ssl::context > & context () noexcept
 Get the client SSL context. More...
 
const std::string & uri () const noexcept
 Get the WebSocket URI address. More...
 
WebSocketSSLClientCorecore () noexcept
 Get the WebSocket client core. More...
 
uint64_t messages_sent () const noexcept
 Get the number messages sent by this client. More...
 
uint64_t messages_received () const noexcept
 Get the number messages received by this client. More...
 
uint64_t bytes_sent () const noexcept
 Get the number of bytes sent by this client. More...
 
uint64_t bytes_received () const noexcept
 Get the number of bytes received by this client. More...
 
bool IsConnected () const noexcept
 Is the client connected? More...
 
bool Connect ()
 Connect the client. More...
 
bool Disconnect (websocketpp::close::status::value code=websocketpp::close::status::normal, const std::string &reason="")
 Disconnect the client. More...
 
bool Reconnect ()
 Reconnect the client. More...
 
size_t Send (const void *buffer, size_t size, websocketpp::frame::opcode::value opcode=websocketpp::frame::opcode::binary)
 Send data to the server. More...
 
size_t Send (const std::string &text, websocketpp::frame::opcode::value opcode=websocketpp::frame::opcode::text)
 Send a text string to the server. More...
 
size_t Send (const WebSocketSSLMessage &message)
 Send a message to the server. More...
 

Protected Member Functions

virtual void onConnected ()
 Handle client connected notification. More...
 
virtual void onDisconnected ()
 Handle client disconnected notification. More...
 
virtual void onReceived (const WebSocketSSLMessage &message)
 Handle message received notification. More...
 
virtual void onError (int error, const std::string &category, const std::string &message)
 Handle error notification. More...
 

Detailed Description

WebSocket SSL client.

WebSocket SSL client is used to read/write data from/into the connected WebSocket SSL server.

Thread-safe.

Examples:
websocket_ssl_chat_client.cpp.

Definition at line 26 of file websocket_ssl_client.h.

Constructor & Destructor Documentation

◆ WebSocketSSLClient() [1/3]

CppServer::Asio::WebSocketSSLClient::WebSocketSSLClient ( std::shared_ptr< Service service,
std::shared_ptr< asio::ssl::context >  context,
const std::string &  uri 
)
explicit

Initialize WebSocket client with a given Asio service, SSL context and server URI address.

Parameters
service- Asio service
context- SSL context
uri- WebSocket URI address
Examples:
websocket_ssl_chat_client.cpp.

Definition at line 14 of file websocket_ssl_client.cpp.

◆ WebSocketSSLClient() [2/3]

CppServer::Asio::WebSocketSSLClient::WebSocketSSLClient ( const WebSocketSSLClient )
delete

◆ WebSocketSSLClient() [3/3]

CppServer::Asio::WebSocketSSLClient::WebSocketSSLClient ( WebSocketSSLClient &&  )
default

◆ ~WebSocketSSLClient()

virtual CppServer::Asio::WebSocketSSLClient::~WebSocketSSLClient ( )
virtualdefault

Member Function Documentation

◆ bytes_received()

uint64_t CppServer::Asio::WebSocketSSLClient::bytes_received ( ) const
inlinenoexcept

Get the number of bytes received by this client.

Definition at line 62 of file websocket_ssl_client.h.

◆ bytes_sent()

uint64_t CppServer::Asio::WebSocketSSLClient::bytes_sent ( ) const
inlinenoexcept

Get the number of bytes sent by this client.

Definition at line 60 of file websocket_ssl_client.h.

◆ Connect()

bool CppServer::Asio::WebSocketSSLClient::Connect ( )

Connect the client.

Returns
'true' if the client was successfully connected, 'false' if the client failed to connect
Examples:
websocket_ssl_chat_client.cpp.

Definition at line 55 of file websocket_ssl_client.cpp.

◆ context()

std::shared_ptr<asio::ssl::context>& CppServer::Asio::WebSocketSSLClient::context ( )
noexcept

Get the client SSL context.

◆ core()

WebSocketSSLClientCore& CppServer::Asio::WebSocketSSLClient::core ( )
inlinenoexcept

Get the WebSocket client core.

Definition at line 53 of file websocket_ssl_client.h.

◆ Disconnect()

bool CppServer::Asio::WebSocketSSLClient::Disconnect ( websocketpp::close::status::value  code = websocketpp::close::status::normal,
const std::string &  reason = "" 
)
inline

Disconnect the client.

Parameters
code- Close code to send (default is normal)
reason- Close reason to send (default is "")
Returns
'true' if the client was successfully disconnected, 'false' if the client is already disconnected

Definition at line 78 of file websocket_ssl_client.h.

◆ id()

const CppCommon::UUID& CppServer::Asio::WebSocketSSLClient::id ( ) const
inlinenoexcept

Get the client Id.

Examples:
websocket_ssl_chat_client.cpp.

Definition at line 44 of file websocket_ssl_client.h.

◆ IsConnected()

bool CppServer::Asio::WebSocketSSLClient::IsConnected ( ) const
inlinenoexcept

Is the client connected?

Definition at line 65 of file websocket_ssl_client.h.

◆ messages_received()

uint64_t CppServer::Asio::WebSocketSSLClient::messages_received ( ) const
inlinenoexcept

Get the number messages received by this client.

Definition at line 58 of file websocket_ssl_client.h.

◆ messages_sent()

uint64_t CppServer::Asio::WebSocketSSLClient::messages_sent ( ) const
inlinenoexcept

Get the number messages sent by this client.

Definition at line 56 of file websocket_ssl_client.h.

◆ onConnected()

virtual void CppServer::Asio::WebSocketSSLClient::onConnected ( )
inlineprotectedvirtual

Handle client connected notification.

Examples:
websocket_ssl_chat_client.cpp.

Definition at line 109 of file websocket_ssl_client.h.

◆ onDisconnected()

virtual void CppServer::Asio::WebSocketSSLClient::onDisconnected ( )
inlineprotectedvirtual

Handle client disconnected notification.

Examples:
websocket_ssl_chat_client.cpp.

Definition at line 111 of file websocket_ssl_client.h.

◆ onError()

virtual void CppServer::Asio::WebSocketSSLClient::onError ( int  error,
const std::string &  category,
const std::string &  message 
)
inlineprotectedvirtual

Handle error notification.

Parameters
error- Error code
category- Error category
message- Error message
Examples:
websocket_ssl_chat_client.cpp.

Definition at line 125 of file websocket_ssl_client.h.

◆ onReceived()

virtual void CppServer::Asio::WebSocketSSLClient::onReceived ( const WebSocketSSLMessage message)
inlineprotectedvirtual

Handle message received notification.

Parameters
message- Received message
Examples:
websocket_ssl_chat_client.cpp.

Definition at line 117 of file websocket_ssl_client.h.

◆ operator=() [1/2]

WebSocketSSLClient& CppServer::Asio::WebSocketSSLClient::operator= ( const WebSocketSSLClient )
delete

◆ operator=() [2/2]

WebSocketSSLClient& CppServer::Asio::WebSocketSSLClient::operator= ( WebSocketSSLClient &&  )
default

◆ Reconnect()

bool CppServer::Asio::WebSocketSSLClient::Reconnect ( )

Reconnect the client.

Returns
'true' if the client was successfully reconnected, 'false' if the client is already reconnected

Definition at line 166 of file websocket_ssl_client.cpp.

◆ Send() [1/3]

size_t CppServer::Asio::WebSocketSSLClient::Send ( const void *  buffer,
size_t  size,
websocketpp::frame::opcode::value  opcode = websocketpp::frame::opcode::binary 
)

Send data to the server.

Parameters
buffer- Buffer to send
size- Buffer size
opcode- Data opcode (default is websocketpp::frame::opcode::binary)
Returns
Count of sent bytes

Definition at line 177 of file websocket_ssl_client.cpp.

◆ Send() [2/3]

size_t CppServer::Asio::WebSocketSSLClient::Send ( const std::string &  text,
websocketpp::frame::opcode::value  opcode = websocketpp::frame::opcode::text 
)

Send a text string to the server.

Parameters
text- Text string to send
opcode- Data opcode (default is websocketpp::frame::opcode::text)
Returns
Count of sent bytes

Definition at line 202 of file websocket_ssl_client.cpp.

◆ Send() [3/3]

size_t CppServer::Asio::WebSocketSSLClient::Send ( const WebSocketSSLMessage message)

Send a message to the server.

Parameters
message- Message to send
Returns
Count of sent bytes

Definition at line 224 of file websocket_ssl_client.cpp.

◆ service()

std::shared_ptr<Service>& CppServer::Asio::WebSocketSSLClient::service ( )
inlinenoexcept

Get the Asio service.

Definition at line 47 of file websocket_ssl_client.h.

◆ uri()

const std::string& CppServer::Asio::WebSocketSSLClient::uri ( ) const
inlinenoexcept

Get the WebSocket URI address.

Definition at line 51 of file websocket_ssl_client.h.


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