带有.NET路由器(WampSharp)的AutoBAHN组件



目前我正在玩Wamp Proto,如果可能的话,我很好奇,因为我无法正常工作:

1.用C#(WampSharp)写的WAMP路由器:

const string location = "ws://127.0.0.1:9999/wsdemo";
try
{
    using (IWampHost host = new DefaultWampHost(location))
    {
        IWampHostedRealm realm = host.RealmContainer.GetRealmByName("realm1");
        host.Open();
        Console.WriteLine("Host is running on : " + location);
    }
}
catch(Exception exc)
{
    Console.WriteLine("Error : " + exc.ToString());
}

2.用python编写的保存组件:

import random
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.util import sleep
from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner
class Component(ApplicationSession):
    """
    An application component that publishes events with no payload
    and with complex payload every second.
    """
    @inlineCallbacks
    def onJoin(self, details):
        print("session attached")
        counter = 0
        while True:
            num = random.randint(0, 100)
            print("publishing : com.myapp.topic1", num)
            self.publish(u'com.myapp.topic1', num)
            counter += 1
            yield sleep(1)

if __name__ == '__main__':
    runner = ApplicationRunner(url=u"ws://127.0.0.1:9999/wsdemo", realm=u"realm1")
    runner.run(Component)

当我运行Python脚本时,我会收到错误:

2017-02-20T19:49:46+0100 Main loop terminated.
2017-02-20T19:49:46+0100 Traceback (most recent call last):
2017-02-20T19:49:46+0100   File "C:Program Files (x86)JetBrainsPyCharm Educational Edition 1.0.1helperspydevpydevd.py", line 2199, in <module>
2017-02-20T19:49:46+0100     globals = debugger.run(setup['file'], None, None)
2017-02-20T19:49:46+0100   File "C:Program Files (x86)JetBrainsPyCharm Educational Edition 1.0.1helperspydevpydevd.py", line 1638, in run
2017-02-20T19:49:46+0100     pydev_imports.execfile(file, globals, locals)  # execute the script
2017-02-20T19:49:46+0100   File "D:/Programming/Astronomy/Dev/ZenithPlatform/backbone/local/tests/wamp.py", line 41, in <module>
2017-02-20T19:49:46+0100     runner.run(Component)
2017-02-20T19:49:46+0100   File "C:Python27libsite-packagesautobahntwistedwamp.py", line 312, in run
2017-02-20T19:49:46+0100     raise connect_error.exception
2017-02-20T19:49:46+0100 twisted.internet.error.ConnectionRefusedError: Connection was refused by other side: 10061: No connection could be made because the target machine actively refused it..

按照http://autobahn.ws/python/wamp/programming.html#rnunning-a-wamp-router

我们创建的组件尝试连接到WAMP路由器 在本地运行,该在端口8080上接受连接,并且 领域领域1。

我们建议的方法是将CrossBar.io用作您的WAMP路由器。有 除了Crossbar.io之外的其他Wamp路由器。

完全可以实现类似的事情吗?

谢谢,
civa

您的使用语句在程序结束之前处置路由器。

只需添加一个console.Readline();在Console.Writeline()语句之后使用范围内的语句。那应该有效。

相关内容

  • 没有找到相关文章