首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有.NET路由器的Autobahn组件(WampSharp)

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

Stack Overflow用户
提问于 2017-02-20 19:08:11
回答 1查看 226关注 0票数 0

目前我正在玩WAMP proto,我很好奇这样的事情是否可能发生,因为我无法让它发挥作用:

1.用c# (WampSharp)编写WAMP路由器:

代码语言:javascript
复制
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编写组件:

代码语言:javascript
复制
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脚本时,我得到了错误:

代码语言:javascript
复制
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路由器。

这样的事情能实现吗?

谢谢,

Civa

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-20 21:15:57

在程序结束之前,使用语句会对路由器进行处理。

只需在Console.ReadLine()语句之后的using作用域中添加一个Console.WriteLine();语句。那应该管用。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42352473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档