简体   繁体   English

如何使用python-socketio从客户端访问套接字ID?

[英]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.

相关问题 如何将 Javascript 客户端连接到 Python-SocketIO 服务器? - How can i connect a Javascript client to a Python-SocketIO server? Python-socketio:如何从服务器向客户端发出消息? - Python-socketio: How to emit message from server to client? Python-socketio:如何将一个客户端连接到多个服务器? - Python-socketio: How to connect one client to multiple servers? python-socketio 客户端到客户端的消息传递 - python-socketio client to client messaging 如果python-socketio是我的项目的一部分,如何注册wsgi - How to register the wsgi if the python-socketio is a part of my project python-socketio 客户端无法获取公共数据,但 NodeJS socket.io-client 没有 - python-socketio client fails to get public data but NodeJS socket.io-client does not electron/socket.io 客户端 - python-socketio/aiohttp 服务器 // 连接失败 - electron/socket.io client - python-socketio/aiohttp server // fail to connect 你可以在 Django 中使用 python-socketio 吗? - Can you use python-socketio for django? 如何从python-socketio连接获取客户端的IP地址,并且仍然能够从程序中的任何位置发出 - How to get the client's IP address from python-socketio connection and still be able to emit from anywhere in the program 如何在线程中运行 python-socketio? - How to run python-socketio in Thread?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM