小编alo*_*nto的帖子

如何使用两个具有高速公路应用程序的线程创建一个python应用程序

我没有为我的问题找到任何解决方案.我需要创建一个带有两个线程的python应用程序,每个线程使用autobahn库连接到WAMP路由器.

跟着我写下我的实验代码:

wampAddress = 'ws://172.17.3.139:8181/ws'
wampRealm = 's4t'

from threading import Thread
from autobahn.twisted.wamp import ApplicationRunner
from autobahn.twisted.wamp import ApplicationSession
from twisted.internet.defer import inlineCallbacks


class AutobahnMRS(ApplicationSession):
    @inlineCallbacks
    def onJoin(self, details):
        print("Sessio attached [Connect to WAMP Router]")

        def onMessage(*args):
            print args
        try:
            yield self.subscribe(onMessage, 'test')
            print ("Subscribed to topic: test")

        except Exception as e:
            print("Exception:" +e)

class AutobahnIM(ApplicationSession):
    @inlineCallbacks
    def onJoin(self, details):
        print("Sessio attached [Connect to WAMP Router]")

        try:
            yield self.publish('test','YOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO')
            print ("Subscribed to topic: test")

        except Exception as e:
            print("Exception:" …
Run Code Online (Sandbox Code Playgroud)

python twisted websocket autobahn wamp-protocol

3
推荐指数
1
解决办法
2305
查看次数

标签 统计

autobahn ×1

python ×1

twisted ×1

wamp-protocol ×1

websocket ×1