kendhia
kendhia

Reputation: 299

Connecting Flask app to a Websocket server

Not able to connect a Flask app as a websocket client to another websocket server.

I tried to look around how to implement this, but the only solution i found is when the connection is Short-lived one-off send-receive.

So, when I make a Long-lived connection, Flask app is not running anymore. I guess the problem, is because both of them are running "forever".

so if run the following code first, flask app won't run, and if I do the opposite the websocket connection won't be established.

 websocket.enableTrace(True)
 ws = websocket.WebSocketApp(config["WS_URI"],
                                on_message = on_message,
                                on_error = on_error,
                                on_close = on_close)
 ws.on_open = on_open

 ws.run_forever() 

a sample Flask app:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "index"

Upvotes: 2

Views: 3094

Answers (1)

kendhia
kendhia

Reputation: 299

The solution I found was to run them on different processes. I wrote a small post explaining the details.

Upvotes: 2

Related Questions