Having problems with "Subscribe"

#1

Hi!

First of all, thank you for sharing your work.

I have a (wierd) problem with autobahnjs. While I can connect to a WebSocket, it seems that for some reason, I can’t subscribe to a topic. What could be the problem?

Can you help me, please, with some suggestions about how can I identify the real issue?

Thank you

0 Likes

#2

Hi!

First of all, thank you for sharing your work.
I have a (wierd) problem with autobahnjs. While I can connect to a
WebSocket, it seems that for some reason, I can't subscribe to a topic.

You need a WAMP server .. a server only implementing WebSocket is not enough.

http://wamp.ws/

···

Am 16.01.2013 09:38, schrieb Marius Matei:

What could be the problem?
Can you help me, please, with some suggestions about how can I identify
the real issue?
Thank you

0 Likes

#3

Wow, quick response. Thank you

I’m using Ratchet as a WAMP implementation. The problem was with firewall and ports. Solved now.
miercuri, 16 ianuarie 2013, 10:55:24 UTC+2, Tobias Oberstein a scris:

···

Am 16.01.2013 09:38, schrieb Marius Matei:

Hi!

First of all, thank you for sharing your work.

I have a (wierd) problem with autobahnjs. While I can connect to a

WebSocket, it seems that for some reason, I can’t subscribe to a topic.

You need a WAMP server … a server only implementing WebSocket is not
enough.

http://wamp.ws/

What could be the problem?

Can you help me, please, with some suggestions about how can I identify

the real issue?

Thank you

0 Likes

#4

I have the ‘same’ problem but I think the wampcraserver is running.

I use this example: https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/authentication/index.html

Then the problem is inside this code:


function onAuth(permissions) {

  ab.log("authenticated!", JSON.stringify(permissions)); <--- this is oke

  session.subscribe(myTopic, onMyEvent); <-- does nothing

};

function onMyEvent(topic, event) {

 ab.log("MyEvent", topic, event); <-- does nothing

};

At the server side I use this code

https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/authentication/server.py

without this part:

webdir = File(".")

web = Site(webdir)

reactor.listenTCP(8080, web)

(I did try this with that code)

···

On Wednesday, January 16, 2013 9:55:24 AM UTC+1, Tobias Oberstein wrote:

Am 16.01.2013 09:38, schrieb Marius Matei:

Hi!

First of all, thank you for sharing your work.

I have a (wierd) problem with autobahnjs. While I can connect to a

WebSocket, it seems that for some reason, I can’t subscribe to a topic.

You need a WAMP server … a server only implementing WebSocket is not
enough.

http://wamp.ws/

What could be the problem?

Can you help me, please, with some suggestions about how can I identify

the real issue?

Thank you

0 Likes

#5

I found ab.debug(true,true)

This gives me this part

WAMP Subscribe autobahn.min.js:62

ws://localhost:9000 [SG1-BlMsYnv4vm9M] autobahn.min.js:62

http://localhost:9000/event autobahn.min.js:62

        function (topic, e) {

console.log(‘YESS’,topic,e);
} autobahn.min.js:62

WS Send autobahn.min.js:59

ws://localhost:9000 [SG1-BlMsYnv4vm9M] autobahn.min.js:59

4 autobahn.min.js:59

[5,“http://localhost:9000/event”]

[stops]

I never see the YESS text in the console.

The wamp server code is only this

import sys

from twisted.internet import reactor, defer

from twisted.python import log

from autobahn.websocket import listenWS

from autobahn.wamp import exportRpc, \

WampServerFactory, \

WampCraServerProtocol

class Hooi(WampCraServerProtocol):

SECRETS = {‘key’: ‘tx5xMrgXtMuatZmkJZ0CuesYLSE6qCxmXDgv6q7rDIo=’}

PERMISSIONS = {‘key’: {

‘pubsub’: [{‘uri’: ‘http://localhost:9000/event/’,

‘prefix’: True,

‘pub’: True,

‘sub’: True}],

‘rpc’: [{‘uri’: ‘http://localhost:9000/procedures/’,

‘call’: True,

‘prefix_name’:‘proc’}]}

}

def onSessionOpen(self):

print “Session open”

override global client auth options

self.clientAuthTimeout = 0

self.clientAuthAllowAnonymous = True

call base class method

WampCraServerProtocol.onSessionOpen(self)

def getAuthPermissions(self, authKey, authExtra):

print “getAuthPermissions”

return permissions which will be granted for the auth key

when the authentication succeeds

return {‘permissions’: self.PERMISSIONS.get(authKey, None),

‘authextra’: {‘salt’: “RANDOM SALT”,

‘keylen’: 32,

‘iterations’: 10000}}

def getAuthSecret(self, authKey):

print “getAuthSecret”

return the auth secret for the given auth key or None when the auth key

does not exist

return self.SECRETS.get(authKey, None)

def onAuthenticated(self, authKey, perms):

print “onAuthenticated”

fired when authentication succeeds

register PubSub topics from the auth permissions

self.registerForPubSubFromPermissions(perms[‘permissions’])

register RPC endpoints (for now do that manually, keep in sync with perms)

if authKey is not None:

self.registerForRpc(self,

http://localhost:9000/procedures/’,

[Hooi.say])

@exportRpc(“say”)

def say(self, txt):

print

return {‘t’:txt}

def onMessage(self, msg, binary):

#print “sending echo:”, msg

#self.sendMessage(msg, binary)

if name == ‘main’:

log.startLogging(sys.stdout)

factory = WampServerFactory(“ws://localhost:9000”, debug = True)

factory.protocol = Hooi

factory.setProtocolOptions(allowHixie76 = True)

listenWS(factory)

webdir = File(".")

web = Site(webdir)

reactor.listenTCP(8080, web)

reactor.run()

···

On Monday, February 25, 2013 4:41:49 PM UTC+1, GC-Martijn B wrote:

I have the ‘same’ problem but I think the wampcraserver is running.

I use this example: https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/authentication/index.html

Then the problem is inside this code:


function onAuth(permissions) {

ab.log(“authenticated!”, JSON.stringify(permissions)); <— this is oke

session.subscribe(myTopic, onMyEvent); <-- does nothing

};

function onMyEvent(topic, event) {

ab.log(“MyEvent”, topic, event); <-- does nothing

};

At the server side I use this code

https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/authentication/server.py

without this part:

webdir = File(".")

web = Site(webdir)

reactor.listenTCP(8080, web)

(I did try this with that code)

On Wednesday, January 16, 2013 9:55:24 AM UTC+1, Tobias Oberstein wrote:

Am 16.01.2013 09:38, schrieb Marius Matei:

Hi!

First of all, thank you for sharing your work.

I have a (wierd) problem with autobahnjs. While I can connect to a

WebSocket, it seems that for some reason, I can’t subscribe to a topic.

You need a WAMP server … a server only implementing WebSocket is not
enough.

http://wamp.ws/

What could be the problem?

Can you help me, please, with some suggestions about how can I identify

the real issue?

Thank you

0 Likes

#6

I'd suggest: try running the unmodified examples first.

Also: you are allowing the client to do pubsub on all topic URIs starting with

'http://localhost:9000/event/'

However, you publish to

"http://localhost:9000/event"

which doesnt start with the former.

Also note that you don't need to adjust your URIs to your server. Those URIs are just identifiers ..

Tobias

···

Am 26.02.2013 10:23, schrieb GC-Martijn B:

I found ab.debug(true,true)

This gives me this part
WAMP Subscribe autobahn.min.js:62 <http://shared.hooi.nl/js/autobahn.min.js>
ws://localhost:9000 [SG1-BlMsYnv4vm9M] autobahn.min.js:62
<http://shared.hooi.nl/js/autobahn.min.js>
http://localhost:9000/event autobahn.min.js:62
<http://shared.hooi.nl/js/autobahn.min.js>
function (topic, e) { console.log('YESS',topic,e); } autobahn.min.js:62
<http://shared.hooi.nl/js/autobahn.min.js>
WS Send autobahn.min.js:59 <http://shared.hooi.nl/js/autobahn.min.js>
ws://localhost:9000 [SG1-BlMsYnv4vm9M] autobahn.min.js:59
<http://shared.hooi.nl/js/autobahn.min.js>
4 autobahn.min.js:59 <http://shared.hooi.nl/js/autobahn.min.js>
[5,"http://localhost:9000/event"]

[stops]
I never see the YESS text in the console.

The wamp server code is only this
import sys

from twisted.internet import reactor, defer
from twisted.python import log

from autobahn.websocket import listenWS

from autobahn.wamp import exportRpc, \
                           WampServerFactory, \
                           WampCraServerProtocol

class Hooi(WampCraServerProtocol):

   SECRETS = {'key': 'tx5xMrgXtMuatZmkJZ0CuesYLSE6qCxmXDgv6q7rDIo='}
   PERMISSIONS = {'key': {
                              'pubsub': [{'uri':
'http://localhost:9000/event/',
                                          'prefix': True,
                                          'pub': True,
                                          'sub': True}],
                              'rpc': [{'uri':
'http://localhost:9000/procedures/',
                                       'call': True,
                                       'prefix_name':'proc'}]}
                          }

   def onSessionOpen(self):
       print "Session open"

       ## override global client auth options
       self.clientAuthTimeout = 0
       self.clientAuthAllowAnonymous = True

       ## call base class method
       WampCraServerProtocol.onSessionOpen(self)

   def getAuthPermissions(self, authKey, authExtra):
       print "getAuthPermissions"
       ## return permissions which will be granted for the auth key
       ## when the authentication succeeds
       return {'permissions': self.PERMISSIONS.get(authKey, None),
               'authextra': {'salt': "RANDOM SALT",
                             'keylen': 32,
                             'iterations': 10000}}

   def getAuthSecret(self, authKey):
       print "getAuthSecret"
       ## return the auth secret for the given auth key or None when the
auth key
       ## does not exist
       return self.SECRETS.get(authKey, None)

   def onAuthenticated(self, authKey, perms):
       print "onAuthenticated"
       ## fired when authentication succeeds

       ## register PubSub topics from the auth permissions
       self.registerForPubSubFromPermissions(perms['permissions'])

       ## register RPC endpoints (for now do that manually, keep in sync
with perms)
       if authKey is not None:
          self.registerForRpc(self,
                              'http://localhost:9000/procedures/',
                              [Hooi.say])

   @exportRpc("say")
   def say(self, txt):
       print
       return {'t':txt}

  # def onMessage(self, msg, binary):
       #print "sending echo:", msg
       #self.sendMessage(msg, binary)

if __name__ == '__main__':

   log.startLogging(sys.stdout)

   factory = WampServerFactory("ws://localhost:9000", debug = True)
   factory.protocol = Hooi
   factory.setProtocolOptions(allowHixie76 = True)
   listenWS(factory)

   webdir = File(".")
   web = Site(webdir)
   reactor.listenTCP(8080, web)

   reactor.run()

On Monday, February 25, 2013 4:41:49 PM UTC+1, GC-Martijn B wrote:

    I have the 'same' problem but I think the wampcraserver is running.

    I use this example:
    https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/authentication/index.html
    <https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/authentication/index.html>

    Then the problem is inside this code:

    function onAuth(permissions) {
    ab.log("authenticated!", JSON.stringify(permissions)); <--- this is oke
    session.subscribe(myTopic, onMyEvent); <-- does nothing
    };
    function onMyEvent(topic, event) {
    ab.log("MyEvent", topic, event); <-- does nothing
    };

    At the server side I use this code
    https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/authentication/server.py
    <https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/authentication/server.py>

    without this part:

    webdir = File(".")
    web = Site(webdir)
    reactor.listenTCP(8080, web)

    (I did try this with that code)

    On Wednesday, January 16, 2013 9:55:24 AM UTC+1, Tobias Oberstein wrote:

        Am 16.01.2013 09:38, schrieb Marius Matei:
         > Hi!
         >
         > First of all, thank you for sharing your work.
         > I have a (wierd) problem with autobahnjs. While I can connect
        to a
         > WebSocket, it seems that for some reason, I can't subscribe
        to a topic.

        You need a WAMP server .. a server only implementing WebSocket
        is not
        enough.

        http://wamp.ws/

         > What could be the problem?
         > Can you help me, please, with some suggestions about how can
        I identify
         > the real issue?
         > Thank you

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Likes