New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
websocket onopen onmessage opclose 回调函数,增加用户数据void* #540
Comments
另外,咨询一下,websocket 客户端,这个headers["Origin"] 是什么意思,headers["Origin"] = "http://example.com/"; 我不填或者写个其他,可以吗? |
std::function可以bind任意的参数,所以不必要像纯c回调函数一样需要添加userdata,你可以使用 |
headers["Origin"]这个头部可以设置成自己的域名,如果服务端不验证这个头部字段,你也可以不填 |
你说的绑定怎么绑定? auto ctx = channel->newContextPtr(); 这样? |
那在服务器里面,怎么获取到这个字段,我看websocket_server_test.cpp里面,没有相关的验证这个头的东西? |
建议你先学习下c++11 lambda函数吧,lambda可以捕获任何参数,包括this指针,这里有示例代码 libhv/examples/websocket_client_test.cpp Line 24 in dd2bb95
|
可以通过req->headers["Origin"]获取这个字端,websocket_server_test.cpp并没有去验证,一些三方的websocket服务可能会验证,如果不验证,你不设置就好了 |
好的。懂了,谢谢。 |
websocket服务端,三个回调函数,都增加第三个参数:用户数据
这样,我初始化server.registerWebSocketService(&ws);的时候,就可以把所谓的上下文添加到回调函数中,回调函数返回时,直接返回对应的用户数据,也就是上下文
同理,客户端也是
The text was updated successfully, but these errors were encountered: