我开始使用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()
..我找不到socket.id
来自客户相同的任何文件javascript
。在javascript
连接成功后,我可以访问 socket.id,如下所示:
const socket = io.connect('https://socketserver.com/', { 'forceNew': true });
socket.on('connect', function () {
alert(socket.id)
})