initial commit
This commit is contained in:
30
third_party/libhv/docs/cn/WebSocketServer.md
vendored
Executable file
30
third_party/libhv/docs/cn/WebSocketServer.md
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
WebSocket 服务端类
|
||||
|
||||
```c++
|
||||
|
||||
// WebSocketServer 继承自 HttpServer
|
||||
class WebSocketServer : public HttpServer {
|
||||
|
||||
// 注册WebSocket业务类
|
||||
void registerWebSocketService(WebSocketService* service);
|
||||
|
||||
};
|
||||
|
||||
// WebSocket业务类
|
||||
struct WebSocketService {
|
||||
// 打开回调
|
||||
std::function<void(const WebSocketChannelPtr&, const HttpRequestPtr&)> onopen;
|
||||
|
||||
// 消息回调
|
||||
std::function<void(const WebSocketChannelPtr&, const std::string&)> onmessage;
|
||||
|
||||
// 关闭回调
|
||||
std::function<void(const WebSocketChannelPtr&)> onclose;
|
||||
|
||||
// 心跳间隔
|
||||
int ping_interval;
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
测试代码见 [examples/websocket_server_test.cpp](../../examples/websocket_server_test.cpp)
|
||||
Reference in New Issue
Block a user