繁体   English   中英

带有.NET路由器(WampSharp)的高速公路组件

[英]Autobahn component with .NET router (WampSharp)

目前,我正在使用WAMP原型,我很好奇这样的事情是否可行,因为我无法使其正常工作:

1,用C#编写WAMP路由器(WampSharp):

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)\JetBrains\PyCharm Educational Edition 1.0.1\helpers\pydev\pydevd.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)\JetBrains\PyCharm Educational Edition 1.0.1\helpers\pydev\pydevd.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:\Python27\lib\site-packages\autobahn\twisted\wamp.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#running-a-wamp-router

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

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

这样的事情可以实现吗?

谢谢,
西瓦

您的using语句会在程序结束之前处理路由器。

只需添加一个Console.ReadLine(); 在Console.WriteLine()语句之后的使用范围内找到该语句。 那应该工作。

暂无
暂无

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

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