2016-04-01 5 views
0

IはアウトバーンでのPythonを使用して、リモートホスト上のクロスバーに接続しようとしている[ツイスト]接続のいずれかハングcrossbar.ioまたは切断する

私の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) 

テストのためにローカルホスト上でクロスバーのインスタンスを実行していますが、アクセスするとすべてが機能します。

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

私はアウトバーンとツイストの次のバージョンでvirtualenvの上でこれを実行することによって、私の問題を修正:最新バージョンがこのように行動された理由を私は知らない

autobahn==0.10.2 
Twisted==15.1.0 

、私はちょうどその私のコードを知っています上記のバージョンでのみ動作します。

関連する問題