6

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:

  • uWSGI 1.0.3-debian
  • python 2.7.3
  • Flask 0.10.1
  • nginx 1.4.3
  • Flask Sockets 0.1
Homer6
  • 15,034
  • 11
  • 61
  • 81

2 Answers2

4

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

roberto
  • 12,723
  • 44
  • 30
  • Thx @roberto I had initially shied away from this because 2.0 was just released a few days before your post. And, I don't like putting major versions into production when they're only a few weeks old. However, this will likely be a good long-term solution. Thank you. – Homer6 Jan 27 '14 at 19:44
  • 1
    I know this is an old question, but where can I find a good example implementation of uwsgi web sockets + flask? – Vingtoft Jan 21 '16 at 15:20
  • I second @Vingtoft comment; I never managed to get this to work, the WebSocket endpoint would always return error 400 in uWSGI – Martin Cejp May 14 '21 at 11:04
0

Although @roberto's solution is likely viable, it's a little too soon from the last major release for me to push it out to production.

I just went back to using socket.io and node in the interim. As time passes, maybe his suggestion will be more viable for me.

Homer6
  • 15,034
  • 11
  • 61
  • 81