Autobahn | Python [asyncio]是否支持安全的网络套接字?

时间:2019-03-27 14:12:34

标签: python autobahn

Autobahn | Python的asyncio变体是否支持安全的WebSocket?使用AutoBahn | Python的安全WebSockets上的文档仅给出了一个Twisted示例:https://autobahn.readthedocs.io/en/latest/websocket/examples.html#secure-websocket

1 个答案:

答案 0 :(得分:0)

它确实起作用。这是带有安全websocket的asyncio组件的示例:

import ssl
from autobahn.asyncio.component import Component


ssl_c = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_c.load_verify_locations(cafile='my_ssl_key.pem')

Component(
    transports={
            'type': 'websocket',
            'url': u'wss://127.0.0.1:8081/',
            'endpoint': {
                'type': 'tcp',
                'host': host,
                'port': 8081,
                'tls': ssl_c
            }
    },
    realm=u'realm1'
)

相关问题