简体   繁体   中英

getting socket id of a client in flask socket.io

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.

From Flask-SocketIO documentation :

The request object defines request.namespace as the name of the namespace being handled, and adds request.sid , defined as the unique session ID for the client connection

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
# ....

考虑使用request.sid ,它从FlaskSocketIO库中填充其值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM