Code Monkey home page Code Monkey logo

Comments (9)

xinsuinizhuan avatar xinsuinizhuan commented on June 12, 2024

另外,咨询一下,websocket 客户端,这个headers["Origin"] 是什么意思,headers["Origin"] = "http://example.com/"; 我不填或者写个其他,可以吗?

from libhv.

ithewei avatar ithewei commented on June 12, 2024

std::function可以bind任意的参数,所以不必要像纯c回调函数一样需要添加userdata,你可以使用ws.onopen = [userdata](...)去捕获参数列表

from libhv.

ithewei avatar ithewei commented on June 12, 2024

headers["Origin"]这个头部可以设置成自己的域名,如果服务端不验证这个头部字段,你也可以不填

from libhv.

xinsuinizhuan avatar xinsuinizhuan commented on June 12, 2024

std::function可以bind任意的参数,所以不必要像纯c回调函数一样需要添加userdata,你可以使用ws.onopen = [userdata](...)去捕获参数列表

你说的绑定怎么绑定? auto ctx = channel->newContextPtr(); 这样?

from libhv.

xinsuinizhuan avatar xinsuinizhuan commented on June 12, 2024

只所以要做用户数据,是因为我一开始设置回调函数时,我就设置了用户数据,您example里面的绑定上下文已经是onopen回调函数里面,来给channel绑定上下文,并且绑定一般都是绑定创建他或者他本身的类指针:
图片

已经到了回调函数里面了,再去绑定,那类指针都找不到了,并且并非要像websocket_server_test.cpp里面,已经到了onopen回调函数了,再去创建一个类指针,给它做绑定,要绑定的是原始或者回调函数本身拥有者的类指针

from libhv.

xinsuinizhuan avatar xinsuinizhuan commented on June 12, 2024

headers["Origin"]这个头部可以设置成自己的域名,如果服务端不验证这个头部字段,你也可以不填

那在服务器里面,怎么获取到这个字段,我看websocket_server_test.cpp里面,没有相关的验证这个头的东西?

from libhv.

ithewei avatar ithewei commented on June 12, 2024

建议你先学习下c++11 lambda函数吧,lambda可以捕获任何参数,包括this指针,这里有示例代码

onopen = [this]() {

from libhv.

ithewei avatar ithewei commented on June 12, 2024

headers["Origin"]这个头部可以设置成自己的域名,如果服务端不验证这个头部字段,你也可以不填

那在服务器里面,怎么获取到这个字段,我看websocket_server_test.cpp里面,没有相关的验证这个头的东西?

可以通过req->headers["Origin"]获取这个字端,websocket_server_test.cpp并没有去验证,一些三方的websocket服务可能会验证,如果不验证,你不设置就好了

from libhv.

xinsuinizhuan avatar xinsuinizhuan commented on June 12, 2024

建议你先学习下c++11 lambda函数吧,lambda可以捕获任何参数,包括this指针,这里有示例代码

onopen = [this]() {

好的。懂了,谢谢。

from libhv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.