Autobahn Application Runner 不是 运行 Apps
Autobahn Application Runner is not running Apps
我对 Autobahn 和 WAMP(Web 应用消息传递协议)还很陌生。
我只是基于 http://autobahn.ws/python/wamp/programming.html and https://github.com/crossbario/crossbarexamples/blob/master/votes/python/votes.py
创建一个简单的应用程序组件
下面是我的服务器端Python
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)
和客户端
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<script>AUTOBAHN_DEBUG = false;</script>
<script src="http://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script>
var connection = new autobahn.Connection({
url: "ws://localhost:8080/ws",
realm: "realm1"
});
connection.onopen = function (session, details) {
session.call("com.myapp.add2", [2,3]).then(session.log);
session.call("com.myapp.add3", [2,3,4]).then(session.log);
};
connection.onclose = function (reason, details) {
console.log("Connection lost: " + reason);
};
connection.open();
</script>
</body>
</html>
错误
看起来这与https://github.com/hwmrocker/hextest/issues/2 but I can't get my head around. I can't even find a sample that works. This one (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 组件在逻辑上 是一个 server-side 组件,但在技术上不是 服务器:它不打开侦听端口或什么,但它连接到WAMP路由器。
我对 Autobahn 和 WAMP(Web 应用消息传递协议)还很陌生。
我只是基于 http://autobahn.ws/python/wamp/programming.html and https://github.com/crossbario/crossbarexamples/blob/master/votes/python/votes.py
创建一个简单的应用程序组件下面是我的服务器端Python
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)
和客户端
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<script>AUTOBAHN_DEBUG = false;</script>
<script src="http://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script>
var connection = new autobahn.Connection({
url: "ws://localhost:8080/ws",
realm: "realm1"
});
connection.onopen = function (session, details) {
session.call("com.myapp.add2", [2,3]).then(session.log);
session.call("com.myapp.add3", [2,3,4]).then(session.log);
};
connection.onclose = function (reason, details) {
console.log("Connection lost: " + reason);
};
connection.open();
</script>
</body>
</html>
错误
看起来这与https://github.com/hwmrocker/hextest/issues/2 but I can't get my head around. I can't even find a sample that works. This one (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 组件在逻辑上 是一个 server-side 组件,但在技术上不是 服务器:它不打开侦听端口或什么,但它连接到WAMP路由器。