0

Im pretty new to Autobahn and WAMP (Web Apps Messaging Protocol).

Im just creating a simple Application Component based on http://autobahn.ws/python/wamp/programming.html and https://github.com/crossbario/crossbarexamples/blob/master/votes/python/votes.py

Below is my Server side Python

from autobahn.asyncio.wamp import (
    ApplicationSession,
    ApplicationRunner
)
from autobahn import wamp

from asyncio import coroutine


class MyComponent(ApplicationSession):
    @wamp.register("com.myapp.add2")
    def add2(self, x, y):
        print("added 2")
        return x + y

    @wamp.register("com.myapp.add3")
    def add3(self, x, y, z):
        print("added 3")
        return x + y + z

    @coroutine
    def onJoin(self, details):
        res = yield from self.register(self)
        print("{} procedures registered.".format(len(res)))

if __name__ == '__main__':
    runner = ApplicationRunner(url="ws://localhost:8080/ws", realm="realm1")
    runner.run(MyComponent)

and the Client side

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
<script>AUTOBAHN_DEBUG = false;</script>
<script src="http://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>

<script>
    var connection = new autobahn.Connection({
        url: "ws://localhost:8080/ws",
        realm: "realm1"
    });

    connection.onopen = function (session, details) {
        session.call("com.myapp.add2", [2,3]).then(session.log);
        session.call("com.myapp.add3", [2,3,4]).then(session.log);
    };

    connection.onclose = function (reason, details) {
        console.log("Connection lost: " + reason);
    };

    connection.open();
</script>
</body>
</html>

Error

enter image description here

Looks like this is similar to https://github.com/hwmrocker/hextest/issues/2 but I can't get my head around. I can't even find a sample that works. This one (https://github.com/tavendo/AutobahnPython/tree/master/examples/asyncio/wamp/wamplet/wamplet1) is similar but it has the same issue as well.

Surprisingly, when I run an external Crossbar sample on the same Port and run the above example, it works like a magic and I can see the results on the console.

I found this one (https://github.com/tavendo/AutobahnPython/blob/master/examples/asyncio/wamp/basic/server.py) but it looks quite complicated.

Please help me out.

Thank you in Advanced.

Eddie
  • 1,043
  • 8
  • 14
  • 1
    Please note, that a lot of examples/docs currently need updating: the "basic WAMP router" included with AutobahnPython (e.g. the option `standalone == True` to `ApplicationRunner`) was moved to Crossbar.io recently: https://groups.google.com/d/msg/autobahnws/bCj7O2G2sxA/6-pioJZ_S_MJ. AutobahnPython is not a WAMP *client* library only - as all the other Autobahn libs. Hence you need an external WAMP router. – oberstet Jan 03 '15 at 11:39

1 Answers1

1

Your code works for me without modification:

enter image description here

Your app consists of 2 WAMP application components: a browser side (using AutobahnJS), and a server side (using AutobahnPython/Python3/asyncio).

For these 2 components to talk to each other, both components need to connect to a WAMP router. I used Crossbar.io.

Note that your Python component is logically a server-side component, but it is not technically a server: it does not open a listening port or what, but it connects to a WAMP router.

oberstet
  • 21,353
  • 10
  • 64
  • 97
  • Thank you very much, this is exactly what I ended up doing as well. I just created an empty crossbar app and run the router before running the above components. – Eddie Jan 03 '15 at 20:34
  • In a few examples, I noticed registering components via a centralized jSON file as well, however, don't you reckon it is a good idea to decentralize it and have a self contained config for each component to avoid the single point of failure issue. – Eddie Jan 03 '15 at 20:45
  • What I did in above was starting the Python app component separately. But Crossbar.io has the *option* to not only operate as a router, but also start and monitor app components in worker processes (and in the future in OS containers - think Docker). The space here is not enough to discuss all aspects and possibilities that this opens and their pros/cons ... – oberstet Jan 04 '15 at 07:51
  • Thanks oberstet. I really appreciate the fantastic tools and Docker. Im desperate to use the next version of crossbar. Im pretty new to network programming but I wish I can help to brush up the documentation and stuffs if I can. – Eddie Jan 04 '15 at 13:21
  • @Eddie if you want to help with docs and/or testing stuff vs the docs, definitely welcome! all docs are generated from the Wiki https://github.com/crossbario/crossbar/wiki which you can edit right away. because anyone can edit, pls take a little care, in particular if in doubt about things - as long as you are learning these things at least. but if you are sufficiently sure an edit is correct, just go ahead! we want to keep the entry bar to contributing as low as possible .. – oberstet Jan 04 '15 at 14:44
  • Let me learn a bit of WAMP, Crossbar, TCP/IP and stuffs first. Hopefully I will be competent enough in a few weeks time. – Eddie Jan 04 '15 at 15:00
  • Sure;) You might also want to join the mailing lists (https://groups.google.com/forum/#!forum/autobahnws, https://groups.google.com/forum/#!forum/wampws, https://groups.google.com/forum/#!forum/crossbario) or come to IRC (#autobahn). In particular the Autobahn mailing list has a lot of users .. also Crossbar.io for historical reasons. – oberstet Jan 04 '15 at 15:14