drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
drogon::WebSocketClient Class Referenceabstract

WebSocket client abstract class. More...

#include <drogon/WebSocketClient.h>

Public Member Functions

virtual WebSocketConnectionPtr getConnection ()=0
 Get the WebSocket connection that is typically used to send messages.
virtual void setMessageHandler (const std::function< void(std::string &&message, const WebSocketClientPtr &, const WebSocketMessageType &)> &callback)=0
 Set messages handler. When a message is received from the server, the callback is called.
virtual void setConnectionClosedHandler (const std::function< void(const WebSocketClientPtr &)> &callback)=0
 Set the connection closing handler. When the websocket connection is closed, the callback is called.
virtual void connectToServer (const HttpRequestPtr &request, const WebSocketRequestCallback &callback)=0
 Connect to the server.
virtual void setCertPath (const std::string &cert, const std::string &key)=0
 Set the client certificate used by the HTTP connection.
virtual void addSSLConfigs (const std::vector< std::pair< std::string, std::string > > &sslConfCmds)=0
 Supplies command style options for SSL_CONF_cmd.
virtual trantor::EventLoop * getLoop ()=0
 Get the event loop of the client;.
virtual void stop ()=0
 Stop trying to connect to the server or close the connection.

Static Public Member Functions

static WebSocketClientPtr newWebSocketClient (const std::string &ip, uint16_t port, bool useSSL=false, trantor::EventLoop *loop=nullptr, bool useOldTLS=false, bool validateCert=true)
 Create a websocket client using the given ip and port to connect to server.
static WebSocketClientPtr newWebSocketClient (const std::string &hostString, trantor::EventLoop *loop=nullptr, bool useOldTLS=false, bool validateCert=true)

Detailed Description

WebSocket client abstract class.

Member Function Documentation

◆ addSSLConfigs()

virtual void drogon::WebSocketClient::addSSLConfigs ( const std::vector< std::pair< std::string, std::string > > & sslConfCmds)
pure virtual

Supplies command style options for SSL_CONF_cmd.

Parameters
sslConfCmdsoptions for SSL_CONF_cmd
Note
this method has no effect if the HTTP client is communicating via unencrypted HTTP
addSSLConfigs({{"-dhparam", "/path/to/dhparam"}, {"-strict", ""}});
virtual void addSSLConfigs(const std::vector< std::pair< std::string, std::string > > &sslConfCmds)=0
Supplies command style options for SSL_CONF_cmd.

◆ newWebSocketClient() [1/2]

WebSocketClientPtr drogon::WebSocketClient::newWebSocketClient ( const std::string & hostString,
trantor::EventLoop * loop = nullptr,
bool useOldTLS = false,
bool validateCert = true )
static

Create a websocket client using the given hostString to connect to server

Parameters
hostStringmust be prefixed by 'ws://' or 'wss://' Examples for hostString:
wss://www.google.com
ws://www.google.com
wss://127.0.0.1:8080/
ws://127.0.0.1
loopif the parameter is set to nullptr, the client uses the HttpAppFramework's main event loop, otherwise it runs in the loop identified by the parameter.
useOldTLSIf the parameter is set to true, the TLS1.0/1.1 are enabled for HTTPS.
validateCertIf the parameter is set to true, the client validates the server certificate when SSL handshaking.
Note
Don't add path and parameters in hostString, the request path and parameters should be set in HttpRequestPtr when calling the connectToServer() method.

◆ newWebSocketClient() [2/2]

WebSocketClientPtr drogon::WebSocketClient::newWebSocketClient ( const std::string & ip,
uint16_t port,
bool useSSL = false,
trantor::EventLoop * loop = nullptr,
bool useOldTLS = false,
bool validateCert = true )
static

Create a websocket client using the given ip and port to connect to server.

Parameters
ipThe ip address of the server.
portThe port of the server.
useSSLIf useSSL is set to true, the client connects to the server using SSL.
loopIf the loop parameter is set to nullptr, the client uses the HttpAppFramework's event loop, otherwise it runs in the loop identified by the parameter.
useOldTLSIf the parameter is set to true, the TLS1.0/1.1 are enabled for HTTPS.
validateCertIf the parameter is set to true, the client validates the server certificate when SSL handshaking.
Returns
HttpClientPtr The smart pointer to the new client object.
WebSocketClientPtr The smart pointer to the WebSocket client.
Note
The ip parameter support for both ipv4 and ipv6 address

◆ setCertPath()

virtual void drogon::WebSocketClient::setCertPath ( const std::string & cert,
const std::string & key )
pure virtual

Set the client certificate used by the HTTP connection.

Parameters
certPath to the certificate
keyPath to the certificate's private key
Note
this method has no effect if the HTTP client is communicating via unencrypted HTTP

◆ setConnectionClosedHandler()

virtual void drogon::WebSocketClient::setConnectionClosedHandler ( const std::function< void(const WebSocketClientPtr &)> & callback)
pure virtual

Set the connection closing handler. When the websocket connection is closed, the callback is called.

Set the connection closing handler. When the connection is established or closed, the callback is called with a bool parameter.

Parameters
callbackThe function to call when the connection is closed.

◆ setMessageHandler()

virtual void drogon::WebSocketClient::setMessageHandler ( const std::function< void(std::string &&message, const WebSocketClientPtr &, const WebSocketMessageType &)> & callback)
pure virtual

Set messages handler. When a message is received from the server, the callback is called.

Parameters
callbackThe function to call when a message is received.

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