miguelgrinberg / flask-sock

Modern WebSocket support for Flask.
MIT License
271 stars 24 forks source link

issues with routing #66

Closed Esser50K closed 11 months ago

Esser50K commented 11 months ago

I'm trying to connect to my websocket endpoint, the connection seems successful (both when running it from a browser or from the terminal via websocat), however the code in the handler never runs.

I have a minimal application to demo the issue, here is the code:

from gevent import monkey, pywsgi
monkey.patch_all()

from geventwebsocket.handler import WebSocketHandler
from geventwebsocket.websocket import WebSocket
from flask import Flask
from flask_cors import CORS
from flask_sock import Sock

app = Flask(__name__)
app.config['SOCK_SERVER_OPTIONS'] = {'ping_interval': 25}
CORS(app)
sock = Sock(app)

@sock.route('/test')
def get_updates(ws: WebSocket):
    print("HERE")

def main():
    try:
        print("Starting WebServer...")
        server = pywsgi.WSGIServer(('127.0.0.1', 9943), app, handler_class=WebSocketHandler)
        server.serve_forever()

    except KeyboardInterrupt:
        pass
    except Exception as e:
        print("ERROR:", e)

if __name__ == '__main__':
    main()

from the terminal I run

websocat ws://127.0.0.1:9943/test

However the result seems to be the same regardless which route I specify on websocat

I get no errors whatsoever, just "silence".

Esser50K commented 11 months ago

Ok the issue was out of date dependencies, not exactly sure which one but I noticed my "Werkzeug" version was still 1.X so I updated everything and it seems to work now.

miguelgrinberg commented 11 months ago

Are you interested in using the gevent-websocket package or Flask-Sock? It seems you are mixing things from both. You should decide which you want to use, then follow the documentation and examples of the chosen package. For Flask-Sock, this repository has some examples that should get you started.