how to publish message from outside WampClientProtocol

#1

Hi ,

In the following code How can I call the publish method outside of the class inheriting WampClientProtocol

import sys

from twisted.python ``import log

from twisted.internet ``import reactor

from autobahn.websocket ``import connectWS

from autobahn.wamp ``import WampClientFactory, \

``WampClientProtocol

class PubSubClient1(WampClientProtocol):

``def onSessionOpen(``self``):

``self``.subscribe(``"http://example.com/simple"``, ``self``.onSimpleEvent)

``self``.sendSimpleEvent()

``def onSimpleEvent(``self``, topicUri, event):

``print "Event"``, topicUri, event

``def sendSimpleEvent(``self``):

``self``.publish(``"http://example.com/simple"``, ``"Hello!"``)

``reactor.callLater(``2``, ``self``.sendSimpleEvent)

if __name__ ``=``= '__main__'``:

``log.startLogging(sys.stdout)

``debug ``= len``(sys.argv) > ``1 and sys.argv[``1``] ``=``= 'debug'

``factory ``= WampClientFactory(``"ws://localhost:9000"``, debugWamp ``= debug)

``factory.protocol ``= PubSubClient1

``connectWS(factory)

``reactor.run()

Thanks,

Akhil

0 Likes

#2

You create your own PubSubFactory1 deriving from WampClientFactory, overriding (the standard Twisted method) buildProtocol, and remembering the protocol instance (of PubSubClient1) you create in buildProtocol somewhere accessible from the code from where you want to call something on the protocol.

/Tobias

···

Am 23.09.2013 17:52, schrieb Akhil Pillai:

Hi ,

In the following code How can I call the publish method outside of the
class inheriting WampClientProtocol

0 Likes

#3

Hi Tobias,

I am new to python ,can you please provide with the code example for the solution

Thanks,

Akhil

···

On Tuesday, 24 September 2013 19:06:42 UTC+5:30, Tobias Oberstein wrote:

Am 23.09.2013 17:52, schrieb Akhil Pillai:

Hi ,

In the following code How can I call the publish method outside of the

class inheriting WampClientProtocol

You create your own PubSubFactory1 deriving from WampClientFactory,
overriding (the standard Twisted method) buildProtocol, and remembering
the protocol instance (of PubSubClient1) you create in buildProtocol
somewhere accessible from the code from where you want to call something
on the protocol.

/Tobias

0 Likes

#4

     > Hi ,
     >
     > In the following code How can I call the publish method outside
    of the
     > class inheriting WampClientProtocol

    You create your own PubSubFactory1 deriving from WampClientFactory,
    overriding (the standard Twisted method) buildProtocol, and remembering
    the protocol instance (of PubSubClient1) you create in buildProtocol
    somewhere accessible from the code from where you want to call
    something
    on the protocol.

    /Tobias

Hi Tobias,

I am new to python ,can you please provide with the code example for the
solution

Here you are:
https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/dirwatch/dirwatch.py

/Tobias

···

Am 24.09.2013 17:18, schrieb Akhil Pillai:

On Tuesday, 24 September 2013 19:06:42 UTC+5:30, Tobias Oberstein wrote:
    Am 23.09.2013 17:52, schrieb Akhil Pillai:

Thanks,
Akhil

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

#5

Hi Tobias ,

Thanks a lot. I got my problem resolved.

Thanks,

Akhil

···

On Friday, 27 September 2013 18:46:34 UTC+5:30, Tobias Oberstein wrote:

Am 24.09.2013 17:18, schrieb Akhil Pillai:

On Tuesday, 24 September 2013 19:06:42 UTC+5:30, Tobias Oberstein wrote:

Am 23.09.2013 17:52, schrieb Akhil Pillai:
 > Hi ,
 >
 > In the following code How can I call the publish method outside
of the
 > class inheriting WampClientProtocol
You create your own PubSubFactory1 deriving from WampClientFactory,
overriding (the standard Twisted method) buildProtocol, and remembering
the protocol instance (of PubSubClient1) you create in buildProtocol
somewhere accessible from the code from where you want to call
something
on the protocol.
/Tobias

Hi Tobias,

I am new to python ,can you please provide with the code example for the

solution

Here you are:

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

/Tobias

Thanks,

Akhil

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