I know that there are options out there for WSGI servers that can handle websockets. Ex: this allows running flask + websockets in gunicorn, which is a WSGI server. But I thought the WSGI spec was only concerned with HTTP? Does the spec mention websockets and if not, how is something like flask-socketio
possible?
The WSGI specification does not define how to work with WebSocket. That did not stop some web servers from adding custom extensions to WSGI to implement this. Gunicorn, uWSGI, Werkzeug, gevent, eventlet and Meinheld all have their own way to support WebSocket in their WSGI implementations. Sadly none of them are compatible with each other.
In case you are curious, the main issue with adding WebSocket support is that WSGI does not pass the actual network socket to the application, because it assumes it will not need it. Obviously this is required for WebSocket because the route needs to be able to freely read and write data. Many of the extensions I referenced above add a custom element to the environ
dictionary with this socket.