WebSocket client abstract class.
More...
#include <drogon/WebSocketClient.h>
|
|
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 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) |
WebSocket client abstract class.
◆ 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
-
| sslConfCmds | options 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
-
| hostString | must be prefixed by 'ws://' or 'wss://' Examples for hostString: |
| loop | if 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. |
| useOldTLS | If the parameter is set to true, the TLS1.0/1.1 are enabled for HTTPS. |
| validateCert | If 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
-
| ip | The ip address of the server. |
| port | The port of the server. |
| useSSL | If useSSL is set to true, the client connects to the server using SSL. |
| loop | If 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. |
| useOldTLS | If the parameter is set to true, the TLS1.0/1.1 are enabled for HTTPS. |
| validateCert | If 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
-
| cert | Path to the certificate |
| key | Path 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
-
| callback | The 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
-
| callback | The function to call when a message is received. |
The documentation for this class was generated from the following file: