我正在尝试使用带有高速公路的Python连接到远程主机上的交叉开关[扭曲]
我正在使用PubSub的修改示例代码:
from __future__ import print_function
from os import environ
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner
class Component(ApplicationSession):
def __init__(self, config=None):
ApplicationSession.__init__(self, config)
print("component created")
def onConnect(self):
print("transport connected")
self.join(self.config.realm)
def onChallenge(self, challenge):
print("authentication challenge received")
@inlineCallbacks
def onJoin(self, details=None):
print("session attached")
self.received = 0
for x in range(1, 501):
sub = yield self.subscribe(self.on_event, u'com.myapp.topic{}'.format(x))
if x % 100 == 0:
print("Subscribed to {} topics".format(x))
def on_event(self, i=None):
print("Got event: {}".format(i))
self.received += 1
self.config.extra for configuration, etc. (see [A])
if self.received > self.config.extra['max_events']:
print("Received enough events; disconnecting.")
self.leave()
def onDisconnect(self):
print("disconnected")
if reactor.running:
reactor.stop()
if __name__ == '__main__':
runner = ApplicationRunner(
url=u"ws://localhost:8080/ws",
realm=u"realm1",
extra=dict(
max_events=5000, # [A] pass in additional configuration
),
)
print(runner.log)
runner.run(Component)
我在localhost上运行了一个crossbar实例进行测试,当我访问它时,一切正常。
2016-04-01T17:26:16+0000 component created
2016-04-01T17:26:16+0000 transport connected
2016-04-01T17:26:16+0000 session attached
(stuff happens here, events get published, until max is reached)
2016-04-01T17:26:19+0000 Received SIGINT, shutting down.
2016-04-01T17:26:19+0000 disconnected
2016-04-01T17:26:19+0000 Main loop terminated.
但是如果我尝试连接到其他主机,会发生两件事: 如果它是一个安全的端口:
2016-04-01T17:26:16+0000 component created
2016-04-01T17:26:16+0000 transport connected
(会话永远不会附加,程序挂起)
如果它是一个不安全的端口:
2016-04-01T17:26:16+0000 component created
2016-04-01T17:26:16+0000 transport connected
2016-04-01T17:26:19+0000 disconnected
2016-04-01T17:26:19+0000 Main loop terminated.
(连接在会话附加之前自动将我踢出去
我正在尝试连接的主机有8080用于安全端口,8081用于不安全。所以我改变的是:
url=u'ws://{hostname}:8080/ws', (or)
url=u'ws://{hostname}:8081/ws',
我想知道我是否遗漏了一些关于WAMP连接的明显信息,或者这可能是我试图连接的交叉开关实例上的配置问题。
答案 0 :(得分:0)
我通过使用以下版本的高速公路和扭曲的virtualenv运行此问题来解决我的问题:
autobahn==0.10.2
Twisted==15.1.0
我不知道为什么最新版本的表现方式如此,我只知道上面的代码只适用于那些版本。