【问题标题】:flask-socketio: limit transport to websocket onlyflask-socketio:仅限于 websocket 的传输
【发布时间】:2016-05-13 23:11:28
【问题描述】:

在flask-socketio中,是否可以强制传输仅是web socket?

按照原协议:

https://github.com/socketio/engine.io 
transports (<Array> String): transports to allow connections to (['polling', 'websocket'])

我的目标是摆脱原来的 HTTP 调用。

最好的,

【问题讨论】:

    标签: flask-socketio


    【解决方案1】:

    看到这篇文章 - Socket.io 1.x: use WebSockets only?

    看起来你无法摆脱原来的 HTTP 调用,但你可以告诉客户端不要使用长轮询。

    var socket = io({transports: ['websocket']});
    

    我找不到使用 Flask-SocketIO 从服务器端禁用它的方法。

    【讨论】:

      【解决方案2】:

      根据 Flask-SoskcetIO 的文档,您可以使用 async_mode 来设置 async_mode。如果您使用 gevent-websocket 安装了 eventlet 或 gevent,则将首先使用 websocket。

             async_mode: The asynchronous model to use. See the Deployment
                         section in the documentation for a description of the
                         available options. Valid async modes are
                         ``threading``, ``eventlet``, ``gevent`` and
                         ``gevent_uwsgi``. If this argument is not given,
                         ``eventlet`` is tried first, then ``gevent_uwsgi``,
                         then ``gevent``, and finally ``threading``. The
                         first async mode that has all its dependencies installed
                         is then one that is chosen.
      

      【讨论】:

        猜你喜欢
        • 2018-12-22
        • 1970-01-01
        • 2019-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-11
        • 2016-04-19
        • 2020-10-31
        相关资源
        最近更新 更多