Files
blackbird/lci/include/net/WebSocketClientSSL.hpp
2026-08-02 20:15:07 +08:00

85 lines
2.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef PMC_NET_WEBSOCKET_CLIENT_SSL_HPP
#define PMC_NET_WEBSOCKET_CLIENT_SSL_HPP
#include "WebSocketClientBase.hpp"
#include <string>
#include <memory>
namespace pmc {
namespace net {
/**
* @brief 基于 Boost.Beast 的异步 WebSocket 客户端(SSL/TLS 版本)
*
* 支持安全的 WebSocket 连接(wss://)
*/
class WebSocketClientSSL : public WebSocketClientBase {
public:
/**
* @brief 构造函数
* @param host 服务器主机名或 IP 地址
* @param port 服务器端口号(通常为 443)
* @param path WebSocket 路径(默认 "/")
*/
WebSocketClientSSL(const std::string& host, const std::string& port, const std::string& path = "/");
/**
* @brief 析构函数
*/
~WebSocketClientSSL();
// 实现 WebSocketClientBase 接口
void setMessageCallback(MessageCallback callback) override;
void setErrorCallback(ErrorCallback callback) override;
void setConnectCallback(ConnectCallback callback) override;
void setCloseCallback(CloseCallback callback) override;
bool connect(int timeout_ms = 5000) override;
void disconnect() override;
bool isConnected() const override;
bool send(const std::string& message) override;
bool sendBinary(const void* data, size_t size) override;
void setAutoReconnect(bool enable, int interval_ms = 3000) override;
void setHeartbeatInterval(int interval_ms = 30000) override;
std::string getHost() const override;
std::string getPort() const override;
std::string getPath() const override;
// SSL/TLS 相关方法
bool isSecure() const override { return true; }
void setVerifyCertificate(bool verify) override;
void setCertificateFile(const std::string& cert_file) override;
void setPrivateKeyFile(const std::string& key_file) override;
void setCertificateAuthorityFile(const std::string& ca_file) override;
/**
* @brief 设置 SSL 上下文选项
* @param options SSL 上下文选项
*/
void setSSLContextOptions(long options);
/**
* @brief 设置密码列表
* @param ciphers 密码列表字符串
*/
void setCiphers(const std::string& ciphers);
/**
* @brief 设置 SNI 主机名
* @param sni_hostname SNI 主机名
*/
void setSNIHostname(const std::string& sni_hostname);
private:
// 前向声明实现类
class Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace net
} // namespace pmc
#endif // PMC_NET_WEBSOCKET_CLIENT_SSL_HPP