我开始使用python-socketio
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()
..而且我找不到来自同一javascript
客户端的任何有关socket.id
的文档。 在连接成功后的javascript
,我可以访问如下所示 socket.id:
const socket = io.connect('https://socketserver.com/', { 'forceNew': true });
socket.on('connect', function () {
alert(socket.id)
})
这似乎是我的疏忽。
您可以sio.eio.sid
访问sid
,但我也会添加一个更高级的选项。