I have a Python server using Flask, that has a websocket connection using Flask-SocketIO . There is a similar question : Send custom data along with handshakeData in socket.io? The idea is to do the same thing but instead of using Node, using Flask. I want the client to send some data in the connect event, for example:
var socket = io("http://127.0.0.1:3000/", { query: "foo=bar" });
I haven't been able to get that custom data, and I can't rely on cookies due to the client's framework. A working solution is to have the connect event as usual, and then, in a custom event, get that information as a payload. But what we would want is to only have to do a connect event. Thanks!
As Miguel suggested in his comment you can simply do
from flask import Flask
from flask import request
app = Flask(__name__)
socketio = SocketIO(app)
@socketio.on('connect')
def connect():
foo = request.args.get('foo')
# foo will be 'bar' when a client connects
socketio.run(app)
on the server side.
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