简体   繁体   English

如何使Autobahn WAMP Python服务器和Javascript客户端协同工作?

[英]how to make Autobahn WAMP Python server & Javascript client work together?

I have a Python Autobahn WAMP server (v. 0.8.8, app code at http://pastebin.com/DfQvaJYF ) working fine with a Python client. 我有一个Python Autobahn WAMP服务器(v。0.8.8,应用程序代码位于http://pastebin.com/DfQvaJYF ),可以与Python客户端正常工作。 Using latest Twisted 13.2. 使用最新的Twisted 13.2。 for both server and client. 对于服务器和客户端。

However, the browser javascript client (autobahn js from CDN, app code at http://pastebin.com/1GGaRP5e ) similarly taken from Autobahn JS examples subscribes to a topic, but does not receive any messages. 但是,类似地从Autobahn JS示例中获取的浏览器javascript客户端(来自CDN的autobahn js,应用程序代码位于http://pastebin.com/1GGaRP5e )订阅了一个主题,但是没有收到任何消息。 There are no errors whatsoever anywhere. 任何地方都没有错误。 Same happens when running the client using Node.js. 使用Node.js运行客户端时,也会发生同样的情况。

Checking the server log, I can see that nothing is indeed transmitted - there are no TX WAMP EVENTs ever, after the js web or the Node.js client connects and subscribes. 检查服务器日志,我发现确实没有传输任何内容-在js Web或Node.js客户端连接并订阅之后,就没有TX WAMP事件。

The WAMP server is running on port 8080, and the JS web client page is served from port 8111. Both on the same host. WAMP服务器在端口8080上运行,并且JS Web客户端页面从端口8111提供服务。两者都在同一主机上。

Found the issue. 找到了问题。 Thank you @oberstet for commenting (see above). 谢谢@oberstet发表评论(见上文)。 While just setting the client realm to suggested default realm1 did not work, that lead me towards the solution. 虽然只是客户端领域设置为建议的默认realm1没有工作,导致我走向解决方案。

The short and simple answer is that the Python WAMP server should always explicitly set the realm . 简短而简单的答案是Python WAMP服务器应始终显式设置领域 This applies at least when the server implements a component that subclasses wamp.ApplicationSession (many or all the examples at the autobahn website). 至少当服务器实现了子类wamp.ApplicationSession的组件时才适用 (在高速公路网站上有许多示例或所有示例)。

In other words, in the server there has to be an onConnect function that joins a realm. 换句话说,在服务器中必须有一个加入领域的onConnect函数。 Without it, 没有它,

  • a similarly constructed Python client (that does not join a realm), will work 一个类似构造的Python客户端(不加入域)将正常工作
  • no (Python or Javascript) client that sets a realm will work 设置领域的任何(Python或Javascript)客户端均不起作用

Some speculation beyond the solution: If one can build a Javascript client that works without setting a realm (example I used requires explicit realm), perhaps such a client would work as well. 解决方案之外的一些推测:如果可以构建一个无需设置领域即可工作的Javascript客户端(我使用的示例需要显式领域),那么这样的客户端也可以工作。 Perhaps the Python WAMP server code is buggy in its setting of default realm. 也许Python WAMP服务器代码的默认领域设置有问题。 Or maybe it's just that the default has been changed. 也许只是默认值已更改。 I don't know. 我不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM