9 #ifndef CPPSERVER_ASIO_WEBSOCKET_SSL_CLIENT_H 10 #define CPPSERVER_ASIO_WEBSOCKET_SSL_CLIENT_H 15 #include "system/uuid.h" 44 const CppCommon::UUID&
id() const noexcept {
return _id; }
47 std::shared_ptr<Service>&
service() noexcept {
return _service; }
49 std::shared_ptr<asio::ssl::context>&
context() noexcept;
51 const std::
string&
uri() const noexcept {
return _uri; }
60 uint64_t
bytes_sent() const noexcept {
return _bytes_sent; }
78 bool Disconnect(websocketpp::close::status::value code = websocketpp::close::status::normal,
const std::string& reason =
"") {
return Disconnect(
false, code, reason); }
92 size_t Send(
const void* buffer,
size_t size, websocketpp::frame::opcode::value opcode = websocketpp::frame::opcode::binary);
99 size_t Send(
const std::string& text, websocketpp::frame::opcode::value opcode = websocketpp::frame::opcode::text);
125 virtual void onError(
int error,
const std::string& category,
const std::string& message) {}
131 std::shared_ptr<Service> _service;
133 std::shared_ptr<asio::ssl::context> _context;
136 websocketpp::connection_hdl _connection;
137 std::atomic<bool> _initialized;
138 std::atomic<bool> _connected;
140 uint64_t _messages_sent;
141 uint64_t _messages_received;
142 uint64_t _bytes_sent;
143 uint64_t _bytes_received;
155 bool Disconnect(
bool dispatch, websocketpp::close::status::value code = websocketpp::close::status::normal,
const std::string& reason =
"");
158 void Connected(websocketpp::connection_hdl connection);
160 void Disconnected(websocketpp::connection_hdl connection);
163 void SendError(std::error_code ec);
171 #endif // CPPSERVER_ASIO_WEBSOCKET_SSL_CLIENT_H virtual void onConnected()
Handle client connected notification.
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...
std::shared_ptr< asio::ssl::context > & context() noexcept
Get the client SSL context.
bool Disconnect(websocketpp::close::status::value code=websocketpp::close::status::normal, const std::string &reason="")
Disconnect the client.
uint64_t messages_sent() const noexcept
Get the number messages sent by this client.
virtual void onError(int error, const std::string &category, const std::string &message)
Handle error notification.
WebSocketSSLClientCore & core() noexcept
Get the WebSocket client core.
C++ Server project definitions.
WebSocketSSLConnection::message_ptr WebSocketSSLMessage
WebSocket SSL message.
virtual void onReceived(const WebSocketSSLMessage &message)
Handle message received notification.
WebSocketSSLClient & operator=(const WebSocketSSLClient &)=delete
const std::string & uri() const noexcept
Get the WebSocket URI address.
uint64_t messages_received() const noexcept
Get the number messages received by this client.
size_t Send(const void *buffer, size_t size, websocketpp::frame::opcode::value opcode=websocketpp::frame::opcode::binary)
Send data to the server.
bool Connect()
Connect the client.
bool Reconnect()
Reconnect the client.
virtual ~WebSocketSSLClient()=default
uint64_t bytes_sent() const noexcept
Get the number of bytes sent by this client.
uint64_t bytes_received() const noexcept
Get the number of bytes received by this client.
virtual void onDisconnected()
Handle client disconnected notification.
bool IsConnected() const noexcept
Is the client connected?
std::shared_ptr< Service > & service() noexcept
Get the Asio service.
const CppCommon::UUID & id() const noexcept
Get the client Id.
WebSocket C++ Library definition.
websocketpp::client< websocketpp::config::asio_tls > WebSocketSSLClientCore
WebSocket SSL client core.