简体   繁体   中英

Flask, Python 3, and WebSockets

How can I serve a websockets endpoint from Flask running on Python 3? This seems near impossible. Note, I do not want SocketsIO or anything like that. Just want to be able, from plain JavaScript following the very simple HTML5 standard, connect to to a Flask endpoint and upgrade it to a Websocket for bidirectional communication. Example JS below

var ws = new WebSocket("ws://localhost:5000/echo");

I assumed this would be a simple matter of pip install ing the right module, but no. Any ideas? Should I write my own Python module for this?

Unfortunately this is currently not supported. Possible workarounds below

  • Go node.js.
  • Go python2
  • Fix the existing flask-sockets module, issue here .
  • Take it on yourself to write a python3 aware python module

您是否查看过Flask-SocketIO提供的功能?

pip install flask-socketio

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM