0

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

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)\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 路由器。

这样的事情能实现吗?

谢谢,
西瓦

4

1 回答 1

2

您的using语句在程序结束之前配置路由器。

只需添加一个 Console.ReadLine(); 在 Console.WriteLine() 语句之后的 using 范围内的语句。那应该行得通。

于 2017-02-20T21:15:57.047 回答