|
NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
WebSocket会话类 更多...
#include <websocket.hpp>
Public 类型 | |
| using | message_handler = function<void(const string&, websocket_opcode)> |
| 消息处理器类型 | |
| using | close_handler = function<void(websocket_status, const string&)> |
| 关闭处理器类型 | |
| using | error_handler = function<void(const exception&)> |
| 错误处理器类型 | |
Public 成员函数 | |
| websocket_session (unique_ptr< tcp_socket > sock, websocket_server *server=nullptr) | |
| 构造函数 | |
| ~websocket_session () | |
| 析构函数 | |
| void | start () |
| 启动会话 | |
| void | close (websocket_status status=websocket_status::NORMAL_CLOSURE, const string &reason="") |
| 关闭连接 | |
| void | stop () |
| 停止会话 | |
| bool | send (const string &data, websocket_opcode opcode=websocket_opcode::TEXT) |
| 发送文本/二进制消息 | |
| bool | send_binary (const string &data) |
| 发送二进制消息 | |
| bool | is_open () const noexcept |
| 检查连接是否开启 | |
| void | set_message_handler (message_handler handler) |
| 设置消息处理器 | |
| void | set_close_handler (close_handler handler) |
| 设置关闭处理器 | |
| void | set_error_handler (error_handler handler) |
| 设置错误处理器 | |
| tcp_socket & | socket () noexcept |
| 获取底层socket引用 | |
| const tcp_socket & | socket () const noexcept |
| 获取底层socket常量引用 | |
| ssl_socket * | ssl_socket_ptr () noexcept |
| 获取SSL socket指针 | |
| const ssl_socket * | ssl_socket_ptr () const noexcept |
| 获取SSL socket常量指针 | |
额外继承的成员函数 | |
| Protected 成员函数 继承自 enable_shared_from_this< websocket_session > | |
| enable_shared_from_this () noexcept | |
| 构造函数 | |
| shared_ptr< websocket_session > | shared_from_this () |
| 获取指向自身的共享指针 | |
WebSocket会话类
表示单个WebSocket连接,负责帧的解析、发送、心跳和生命周期管理。
使用示例:
在文件 websocket.hpp 第 211 行定义.
|
explicit |
构造函数
| sock | TCP/SSL socket |
| server | 所属服务器 |
引用了 websocket_session().
被这些函数引用 websocket_session() , 以及 ~websocket_session().
| void websocket_session::close | ( | websocket_status | status = websocket_status::NORMAL_CLOSURE, |
| const string & | reason = "" ) |
|
inlinenoexcept |
| bool websocket_session::send | ( | const string & | data, |
| websocket_opcode | opcode = websocket_opcode::TEXT ) |
|
inline |
发送二进制消息
| data | 消息数据 |
在文件 websocket.hpp 第 308 行定义.
引用了 BINARY, data(), send() , 以及 send_binary().
被这些函数引用 send_binary().
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |