GithubHelp home page GithubHelp logo

Comments (13)

lesismal avatar lesismal commented on June 15, 2024

感谢关注!
不支持fasthttp系的,以前想支持fasthttp但因为fasthttp相关的类型字段没有导出,而且fasthttp基于兼容性、没法修改相关:
valyala/fasthttp#1239

而且就性能来说,不管是基于fasthttp系还是基于标准库,Upgrade后、Conn都是被websocket接管、读写和逻辑都是由websocket库本身处理的了,所以后续的性能与fasthttp或者标准库已经无关了。

倒是可以修改websocket一些内容、单独package去支持fasthttp系的,但是无法有效利用nbio的更多功能、比如不同的IO模式的优势:
https://github.com/lesismal/nbio/releases/tag/v1.3.5
所以修改的意愿不是特别强,我过阵子不忙了看下大概要修改多少,如果修改不大,也可以考虑单开个repo去支持fasthttp websocket

from nbio.

lesismal avatar lesismal commented on June 15, 2024

如果你们的websocket是单独的服务、没有与http接口用同一个服务,直接用nbio的就可以了,如果是与http接口一起的,我再想能不能Hijack的方式hack一下,但是需要业务自己去处理一部分Upgrade逻辑,代码也是不太美观

from nbio.

feng99 avatar feng99 commented on June 15, 2024

from nbio.

lesismal avatar lesismal commented on June 15, 2024

这是fasthttp基于gorilla改造的基于fasthttp的,fiber只要拿到fasthttp.RequestCtx应该就可以直接用了:
https://github.com/fasthttp/websocket

fibber的请求转换为net/http我还没试过,ws这块主要是Upgrade流程+接管conn就可以了

from nbio.

lesismal avatar lesismal commented on June 15, 2024

看了下,fasthttp Upgrade直接回调把conn传递给用户的handler了,所以好像可以搞:
https://github.com/fasthttp/websocket/blob/417207d494e8a883b46ae3193fce4c6e9c3d80d5/server_fasthttp.go#L184

from nbio.

feng99 avatar feng99 commented on June 15, 2024

from nbio.

lesismal avatar lesismal commented on June 15, 2024

看了下,fasthttp Upgrade直接回调把conn传递给用户的handler了,所以好像可以搞: https://github.com/fasthttp/websocket/blob/417207d494e8a883b46ae3193fce4c6e9c3d80d5/server_fasthttp.go#L184

nbio的想精简还是要做下单**剪。直接从 fasthttp/websocket的Upgrade后的Conn里取出conn给nbio的websocket用也可以,类似这里:
#240 (comment)
但是多整了一道就有点别扭

from nbio.

lesismal avatar lesismal commented on June 15, 2024

如果转换器ok,那应该就可以,这个adaptor我收藏了,感谢,哈哈哈
咱试试这个转换器能不能拉通

from nbio.

feng99 avatar feng99 commented on June 15, 2024

from nbio.

lesismal avatar lesismal commented on June 15, 2024

试了下,好像是不行,这个adaptor、fasthttp没有实现 http.Hijacker:

2023/02/25 22:16:35 Upgrade failed: websocket: response does not implement http.Hijacker

from nbio.

lesismal avatar lesismal commented on June 15, 2024

如果想省事,可以直接用这个:
https://github.com/fasthttp/websocket

from nbio.

feng99 avatar feng99 commented on June 15, 2024

感谢您的回复
这个demo符合我的基本需求 略微改了改 搞定了.
https://github.com/gofiber/recipes/tree/master/websocket-chat

from nbio.

lesismal avatar lesismal commented on June 15, 2024

好的,它这个就是用的 github.com/fasthttp/websocket ,在gorilla基础上改的,够用了

from nbio.

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.