[英]How can i connect a Javascript client to a Python-SocketIO server?
[英]How can I access my socket id from client with python-socketio?
我開始使用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()
..並且我從客戶端相同的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
,但是我還將添加一個更高級的選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.