WAMP with longpoll transport

#1

Hi all,

I’m trying out the new WAMP over longpoll transport stuff, and I’m running into a weird issue. I am able to run the initial crossbar example without a problem as follows:

pip install -U crossbar
crossbar init --template longpoll
crossbar start

This demo application works as expected. Then I removed the websocket transport from the config.json and from the client side connection configuration to force the use of longpolling, and everything is still fine and now only the longpolling transport is used. Still all good.

Next, I add registry of an rpc method on the python backend, comment out the subscription on the client side, and replace it with an rpc method call, and this seems to cause a problem. The rpc method returns the correct value to the client side, but the session seems to be closed immediately with the following information:

Connection gone: lost ({“reason”:null,“message”:null,“retry_delay”:1.4736575047577705,“retry_count”:1,“will_retry”:true}) (index):72

Connected: {“type”:“longpoll”,“url”:“http://localhost:8080/lp/8LrQjyR6nIm3Ytck",“protocol”:"wamp.2.json”}

Because of the retry, the connection/rpc-call/disconnect sequence happens in a loop for a long time. I am including the three files I modified below, in case that helps anyone to see what I could be doing wrong.

  1. config.json:

{

“controller”: {

},

“workers”: [

  {

     "type": "router",

     "options": {

        "pythonpath": [".."]

     },

     "realms": [

        {

           "name": "realm1",

           "roles": [

              {

                 "name": "anonymous",

                 "permissions": [

                    {

                       "uri": "*",

                       "publish": true,

                       "subscribe": true,

                       "call": true,

                       "register": true

                    }

                 ]

              }

           ]

        }

     ],

     "transports": [

        {

           "type": "web",

           "endpoint": {

              "type": "tcp",

              "port": 8080

           },

           "paths": {

              "/": {

                 "type": "static",

                 "directory": "../web"

              },

              "lp": {

                 "type": "longpoll",

                 "options": {

                    "debug": true,

                    "session_timeout": 30

                 }

              }

           }

        }

     ],

     "components": [

        {

           "type": "class",

           "classname": "backend.AppSession",

           "realm": "realm1",

           "role": "anonymous"

        }

     ]

  }

]

}

  1. backend.py:

from twisted.internet.defer import inlineCallbacks

from autobahn.twisted.util import sleep

from autobahn.twisted.wamp import ApplicationSession

from autobahn.wamp.exception import ApplicationError

class AppSession(ApplicationSession):

@inlineCallbacks

def onJoin(self, details):

    ## REGISTER a procedure for remote calling
···
    ##

    def add2(x, y):

        print("add2() called with {} and {}".format(x, y))

        return x + y

    reg = yield self.register(add2, 'com.example.add2')

    print("procedure add2() registered")

    ## PUBLISH every second .. forever

    ##

    counter = 0

    while True:

        ## PUBLISH an event

        ##

        yield self.publish('com.example.oncounter', counter)

        print("published to 'oncounter' with counter {}".format(counter))

        counter += 1

        yield sleep(1)
  1. index.html:
  <meta charset="UTF-8">
  <h1>WAMP Longpoll Transport Example</h1>

  <p>Open JavaScript console to watch output.</p>

  <button onclick="open_session()">Open Session</button>

  <button onclick="close_session()">Close Session</button>

  <script>AUTOBAHN_DEBUG = false;</script>

  <script src="autobahn.min.js"></script>

  <script>

     console.log("Running on AutobahnJS", autobahn.version);

     var connection = new autobahn.Connection({

        transports: [

           {

              'type': 'longpoll',

              'url': 'http://' + document.location.host + '/lp',

           }

        ],

        realm: 'realm1'

     });

     var close_session;

     // fired when connection is established and session attached

     //

     connection.onopen = function (session, details) {

        console.log("Connected: " + JSON.stringify(connection.transport.info));

        close_session = function () {

           session.leave();

           //session.leave("wamp.close.normal", "I am fed up!!");

        }

        // SUBSCRIBE to a topic and receive events

        //

        function on_counter (args) {

           var counter = args[0];

           console.log("on_counter() event received with counter " + counter);

        }

        // Now call an rpc method:

        console.log("About to call an rpc method");

        session.call('com.example.add2', [1, 1]).then(function (result) {

           console.log("Result of calling rpc method:");

           console.log(result);

        }, function (err) {

           console.log("Unable to call rpc method")

        })

     };

     // fired when connection was lost (or could not be established)

     //

     connection.onclose = function (reason, details) {

        console.log("Connection gone: " + reason + " (" + JSON.stringify(details) + ")");

        // return true to stop retrying ..

        //return true;

     }

     // open the connection

     //

     function open_session() {

        connection.open();

     }

  </script>

Thanks!

Scott

0 Likes