I have an existing app running uwsgi/flask behind nginx. I want to integrate websockets into the same app. Flask sockets looks promising, so I'm trying that.
Flask sockets briefly mentions running gevent-websocket, but no sample code is provided to integrate an existing app into this setup. I've also tried several combinations of gevent-websocket with my existing flask app, but I still keep getting 500s. Additionally, it would be nice if I could find out the nature of the 500s, but the errors don't show up in the uwsgi log, as they do for the existing flask app. So, if you have any debugging dips to show a tracedump, that'd be great.
Can anyone help me get a simple echo route working with this setup? Thanks in advance.
FYI, I'm currently using:
In flask the conventional name for the application is app but uWSGI looks for application by default. That's why we create an alias for our app in the last line.
The WebSocket’s can be implemented with all server-side technologies, I am using Flask and Socket-IO modules from Python. First of all, will start by setting up the virtual environment for our sample project. Create a project folder. Create a requirments.txt file into the project folder. Add below code into requirments.txt.
If gevent or eventlet is used in conjunction with uwsgi, the native websocket implementation from uwsgi is used. In my case, I used socket.io on the client, which uses http polling, therefore when I tried to use uwsgi, the server expected a native websocket connection and did not have anything that handled the http polling.
If UWSGI is used, native websockets are used (ws). If gevent or eventlet is used in conjunction with uwsgi, the native websocket implementation from uwsgi is used.
If you upgrade to uWSGI 2.0 you get websockets support for free without the need of additional frameworks and with gevent compatibility. More important you get a really fast implementation (suitable for gaming):
http://uwsgi-docs.readthedocs.org/en/latest/WebSockets.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With