简体   繁体   中英

Autobahn component with .NET router (WampSharp)

At the moment I'm playing with the WAMP proto, and I'm curious if something like this is possible, because I can't get it to work:

1.Having WAMP router written in c# (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.Having component written in 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)

When I run python script, I'm getting the error :

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..

As per http://autobahn.ws/python/wamp/programming.html#running-a-wamp-router

The component we've created attempts to connect to a WAMP router running locally which accepts connections on port 8080, and for a realm realm1.

Our suggested way is to use Crossbar.io as your WAMP router. There are other WAMP routers besides Crossbar.io as well.

Could something like this be achieved at all?

Thanks,
Civa

Your using statement disposes the router before the program ends.

Just add a Console.ReadLine(); statement inside the using scope after the Console.WriteLine() statement. That should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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