getting socket id of a client in flask socket.io
10,171
Solution 1
From Flask-SocketIO documentation:
The request object defines
request.namespace
as the name of the namespace being handled, and addsrequest.sid
, defined as the unique session ID for the client connection
Solution 2
Consider using request.sid
which gets its value populated from the FlaskSocketIO library.
Solution 3
I found it is possible in flask too.
In the flask's request
object there is a socket object which has an id.
from flask import request
# ....
@socketio.on('connect')
def onConnect():
currentSocketId = request.namespace.socket.sessid
# ....
Comments
-
Muatik almost 2 years
Is there a way to get socket id of current client? I have seen it is possible to get socket id in node.js. But it seems flask's socket.io extension is a little bit different than node's socketio.