我正在尝试连接到两个WebSockets(带有URI wss://domainA.com的WebSocket A和带有URI wss://domainB.com/path的WebSocket B),使用在asyncio上运行的Autobahn,如{{3 }}。
我已经像这样创建了一个WebSocketClientProtocol:
from autobahn.asyncio.websocket import WebSocketClientProtocol
class ClientProtocol(WebSocketClientProtocol):
def onConnect(self, response):
print("Connected to Server: {}".format(response.peer))
并使用asyncio连接连接到WebSocket:
from autobahn.asyncio.websocket import WebSocketClientFactory
import asyncio
factory = WebSocketClientFactory()
factory.protocol = ClientProtocol
loop = asyncio.get_event_loop()
coro = loop.create_connection(factory, 'domainA.com', 80)
loop.run_until_complete(coro)
loop.run_forever()
loop.close()
我能够连接到WebSocket A,但用domainA.com
替换domainB.com/path
连接到WebSocket B会导致错误gaierror: [Errno 8] nodename nor servname provided, or not known.
我知道WebSocket B正在工作,因为我可以使用不同的库连接到它。此外,仅使用domainB.com/path
替换domainB.com
会导致connection was closed uncleanly (WebSocket connection upgrade failed (301 - MovedPermanently))