最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】flask中实现websocket

Flask crifan 8145浏览 0评论

需要在Flask中实现Websocket,以便于实现服务器和客户端的实时数据沟通。

搜:

flask websocket

参考:

Welcome to Flask-SocketIO’s documentation! — Flask-SocketIO documentation

GitHub – miguelgrinberg/Flask-SocketIO: Socket.IO integration for Flask applications.

GitHub – kennethreitz/flask-sockets: Elegant WebSockets for your Flask apps.

-》

总体感觉:

还是miguelgrinberg的Flask-SocketIO更好用。

不过,也还是先去简单对比一下:

【整理】Flask中的Websocket库:Flask-SocketIO vs Flask-Sockets

然后想办法去试试:Flask-SocketIO

【未解决】尝试使用Flask-SocketIO去实现Websocket

但是结果出错了:

【已解决】websocket启动出错:gunicorn.errors.HaltServer HaltServer App failed to load 4

再去想办法搞清楚,是不是:

Flask-Restful中,如何支持:Flask-Restful

搜:

Flask-Restful Flask-SocketIO

python – Flask: A RESTful API and SocketIO Server – Stack Overflow

http://stackoverflow.com/questions/32545634/flask-a-restful-api-and-socketio-server

python – To implement a web socket feature with Flask-Restful (REST Api) on the server side – Stack Overflow

http://stackoverflow.com/questions/34735195/to-implement-a-web-socket-feature-with-flask-restful-rest-api-on-the-server-si

Flask-SocketIO, Background Threads , Jquery, Python Demo – Timmy Reilly’s Blog

http://timmyreilly.azurewebsites.net/flask-socketio-and-more/

希望用flask作为中介让python和js交互,大家有什么比较好的实践经验没? – 知乎

https://www.zhihu.com/question/27194154

Miguel Grinberg (miguelgrinberg) on GitHub – Libraries.io

https://libraries.io/github/miguelgrinberg

Flask-SocketIO Notifications |

http://blog.fossasia.org/flask-socketio-notifications/

    var namespace = ‘/notifs’;
    var socket = io.connect(location.protocol + "//" + location.host + namespace, {reconnection: false});

【未解决】Simple WebSocket Client测试Flask的websocket显示OPENING且弹出undefined对话框

然后还是没解决。

继续去尝试:

【未解决】Flask-SocketIO测试出错:WebSocket connection to failed Error during WebSocket handshake Unexpected response code 400

要不抽空去试试:

Simple Websocket echo client/server with Flask and gevent / gevent-websocket · GitHub

https://gist.github.com/lrvick/1185629

GitHub – kennethreitz/flask-sockets: Elegant WebSockets for your Flask apps.

https://github.com/kennethreitz/flask-sockets

Flask 如何实现websocket

python使用websocket的几种方式 | 惊鸟的技术小站

http://letus.club/2016/04/10/python-websocket/

到时候也可以考虑试试这个:

GitHub – zeekay/flask-uwsgi-websocket: High-performance WebSockets for your Flask apps powered by uWSGI.

https://github.com/zeekay/flask-uwsgi-websocket

WebSocket with Flask

https://blog.shonenada.com/post/websocket-with-flask/

【已解决】使用Flask-Sockets去实现Flask中的Websocket

然后,对于之前安装了,但是没用到的库,都去删除掉:

pip uninstall Flask-SocketIO

pip uninstall python-socketio

pip uninstall python-engineio

注:

flask-sockets需要依赖gevent

好像gevent是需要依赖greenlet

的。

所以不删。

转载请注明:在路上 » 【已解决】flask中实现websocket

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.167 seconds, using 22.00MB memory