How to use custom id as session id in Flask Socket IO

不羁岁月 提交于 2021-01-29 08:54:44

问题


I am using flask socket-io for a basic chat app. But I have a problem. When my device connect to server, flask give to device a session id. But after disconnect and again connect, session id changes. So, this device can't receive old room's messages. I thought if I'd do if I assign custom session id to device.Is it true? Or what is your suggestions?


回答1:


The session ids are supposed to be unique, even when a client reconnects. There is no way for an application to choose these ids, they are random numbers chosen by the server.

What you need to do is map a session id to your user information in the connect event, and remove the mapping in the disconnect event. That way at any time you can find out what session id a user is currently on. If you need specific room assignments, those need to be done upon connection, and undone on disconnection.



来源:https://stackoverflow.com/questions/53402185/how-to-use-custom-id-as-session-id-in-flask-socket-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!