Best Option Currently Available For Websockets With Flask On Python3
Solution 1:
First of all, note that Flask-SocketIO is different from the other two. It wraps the Socket.IO protocol, not raw WebSocket. This enables it to support a WebSocket-like interface emulated with HTTP long-polling for clients that do not support the WebSocket protocol.
Speaking of Flask-SocketIO, note that this extension is about to receive a major overhaul.
The current official release (0.6) depends on gevent, gevent-socketio and gevent-websocket. Unfortunately gevent-socketio as a project has long been dead and is stuck on a very old version of the Socket.IO protocol, which forces you to use an ancient Javascript client.
The upcoming Flask-SocketIO release 1.0 is a complete rewrite that is mostly compatible with the 0.6 release, but it has support for Python 2 and Python 3 and sports a design that allows different mechanisms to be used for networking and concurrency. The gevent-socketio dependency from version 0.6 is replaced with two new packages called python-socketio and python-engineio, which implement the current version of the Socket.IO protocol, and support all the official Socket.IO clients (Javascript, Swift and C++).
As far as low-level dependencies, you have basically three options:
Eventlet
Eventlet is by far the most performant and stable option, on both Py2 and Py3. WebSocket support is native to eventlet, so just installing eventlet in your virtualenv enables Flask-SocketIO to work in the most optimal configuration.
gevent and gevent-websocket
If for any reason you prefer gevent, that also works, but in my tests it does not perform as good as eventlet. If you want to have access to WebSocket when using gevent, then you also need to install package gevent-websocket. Both gevent and gevent-websocket have been ported to Python 3, but it is all too recent.
Werkzeug (or any other multi-threaded WSGI compatible server)
You can also use Flask's own web server. In this mode, the extension only works in long-polling mode. Performance is obviously terrible compared to the other two, but for development and debugging it is nice to be able to get everything working without having to run eventlet or gevent, with all the complexities they bring.
As of today (10/4/2015), there is a fully functional beta release of the new Flask-SocketIO extension. An official release is coming soon. You can install the beta release with:
pip install flask-socketio==1.0b1
The code is available on the 1.0 branch of the git repo: https://github.com/miguelgrinberg/Flask-SocketIO/tree/v1.0.
Disclaimer: I'm sure this is clear by now, but just in case, note that I'm the author of Flask-SocketIO, python-socketio and python-engineio.
Post a Comment for "Best Option Currently Available For Websockets With Flask On Python3"