私はautobahn pythonを使い始めたばかりで、ヘルパーApplicationRunner
クラスを使用して基本的な接続を行っています。私の意図は、一度接続し、メッセージを送信してから終了することです。これは、私が書いているスクリプトで行う必要があるすべてです。私が遭遇した問題は、アプリケーションが開始された後にアプリケーションをシャットダウンする方法が明らかではないように思われることです。ここでのアドバイスを使用して、グローバルリアクターにアクセスして を呼び出しましreactor.stop()
たが、もっと良い方法があります。以下のスクリプトを確認してください。すべてのコメントを歓迎します。
from autobahn.twisted.wamp import ApplicationRunner, ApplicationSession
class Example(ApplicationSession):
def __init__(self, config=None):
ApplicationSession.__init__(self, config)
def onJoin(self, details):
self.register(self)
# publish something here
from twisted.internet import reactor
reactor.stop()
runner = ApplicationRunner(u"ws://example_address", u"example_realm")
try:
runner.run(Example)
except Exception as e:
print('Couldn\'t connect to WAMP router because: "{}"'.format(e))