[英]How can I access my socket id from client with python-socketio?
I start using python-socketio
connect socketIO
nodejs
server instead of javascript
, I face problem with socket id: 我开始使用python-socketio
connect socketIO
nodejs
服务器而不是javascript
,我遇到套接字ID问题:
class LoginSocket(socketio.ClientNamespace):
def on_connect(self):
print('connected to server')
# I need get socket id here to emit to server
# sio.disconnect()
def on_python(self, *args, **kwargs):
print(args, kwargs, 'xxxxxxxxxxxxxxxxxxxxxx')
def on_disconnect(self):
print('disconnected from server')
sio = socketio.Client()
sio.register_namespace(LoginSocket('/'))
if __name__ == '__main__':
sio.connect('https:/sitename.com/')
sio.wait()
..and I can't find any document about socket.id
from client same javascript
. ..并且我从客户端相同的javascript
找不到任何有关socket.id
文档。 In javascript
after connect success I can access socket.id like below: 连接成功后,在javascript
,我可以如下访问socket.id:
const socket = io.connect('https://socketserver.com/', { 'forceNew': true });
socket.on('connect', function () {
alert(socket.id)
})
This appears to be an omission on my part. 对我而言,这似乎是一个遗漏。
You can access the sid
as sio.eio.sid
, but I will add a more high-level option as well. 您可以通过sio.eio.sid
来访问sid
,但是我还将添加一个更高级的选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.