Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 402
Muatik Avatar asked Nov 27 '14 20:11

Muatik


People also ask

How do I find the Socket id in Python?

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.

What is Socket.IO in Flask?

Flask-SocketIO gives Flask applications access to low latency bi-directional communications between the clients and the server.

What is the difference between Socket.IO and Socket.IO client?

socket-io. client is the code for the client-side implementation of socket.io. That code may be used either by a browser client or by a server process that is initiating a socket.io connection to some other server (thus playing the client-side role in a socket.io connection).


2 Answers

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

like image 92
Marco Lavagnino Avatar answered Sep 30 '22 13:09

Marco Lavagnino


Consider using request.sid which gets its value populated from the FlaskSocketIO library.

like image 24
Succ MyDik Avatar answered Sep 30 '22 12:09

Succ MyDik