#pragma once #include "http_define.h" #if USE_NET_HTTP_WS == 1 #include #include #include "base/define.h" #include "base/error.h" class wsserver_lst; namespace ylib { namespace network { namespace http { /// /// WebSocket服务器 /// class wsserver:public ylib::error_base { public: wsserver(); ~wsserver(); /// /// 启动 /// /// /// /// /// /// bool start(ushort port, bool ssl = false,const std::string& ssl_key = "", const std::string& ssl_pem = ""); /// /// 停止 /// void stop(); /// /// 发送 /// bool send(int64 conn, std::string_view value); /// @brief 断开连接 /// @param conn void disconn(int64 conn); void on_accept(std::function callback) { m_callback_accept = callback; } void on_recv(std::function callback) { m_callback_recv = callback; } void on_close(std::function callback) { m_callback_close = callback; } friend class wsserver_lst; private: // 端口 ushort m_port = 0; // 是否为SSL bool m_ssl = false; // SSL-KEY std::string m_ssl_key; // SSL-PEM std::string m_ssl_pem; // 监听器 wsserver_lst* m_listener = nullptr; // HPServer void* m_server = nullptr; public: std::function m_callback_accept; std::function m_callback_recv; std::function m_callback_close; }; } } } #endif