我对高速公路和WAMP(网络应用程序消息传递协议)相当陌生。在
我只是基于http://autobahn.ws/python/wamp/programming.html和{a2}创建一个简单的应用程序组件
from autobahn.asyncio.wamp import (
ApplicationSession,
ApplicationRunner
)
from autobahn import wamp
from asyncio import coroutine
class MyComponent(ApplicationSession):
@wamp.register("com.myapp.add2")
def add2(self, x, y):
print("added 2")
return x + y
@wamp.register("com.myapp.add3")
def add3(self, x, y, z):
print("added 3")
return x + y + z
@coroutine
def onJoin(self, details):
res = yield from self.register(self)
print("{} procedures registered.".format(len(res)))
if __name__ == '__main__':
runner = ApplicationRunner(url="ws://localhost:8080/ws", realm="realm1")
runner.run(MyComponent)
看起来这和https://github.com/hwmrocker/hextest/issues/2很相似,但我的头都转不过来了。我甚至找不到有效的样本。这个(https://github.com/tavendo/AutobahnPython/tree/master/examples/asyncio/wamp/wamplet/wamplet1)很相似,但也有相同的问题。在
令人惊讶的是,当我在同一个端口上运行一个外部Crossbar示例并运行上面的示例时,它就像一个魔术,我可以在控制台上看到结果。在
我找到了这个(https://github.com/tavendo/AutobahnPython/blob/master/examples/asyncio/wamp/basic/server.py),但看起来很复杂。在
请帮帮我。在
先谢谢你。在
你的代码不经修改就可以为我工作:
你的应用程序由2个WAMP应用程序组件组成:浏览器端(使用AutobahnJS)和服务器端(使用AutobahnPython/Python3/asyncio)。在
要使这两个组件相互通信,两个组件都需要连接到WAMP路由器。我用了Crossbar.io。在
请注意,Python组件在逻辑上是一个服务器端组件,但从技术上讲,它是一个服务器端组件:它不打开侦听端口或什么,但它将连接到WAMP路由器。在
相关问题 更多 >
编程相关推荐