Hi Murphy,

Could you please give me links/paths to a simple JSON messenger example in
NOX?

Thanks,
Neha

On Tue, Jul 24, 2012 at 10:02 PM, Murphy McCauley <[email protected]
> wrote:

> The STOMP library uses threads from Python, which NOX does not support.
>  This will make usage of the library relatively difficult -- you'll need to
> add support for multithreaded Python to NOX, or you'll need to rewrite the
> library (or possibly just call it in a very unusual way) -- probably
> rewriting it to use Twisted (which NOX does support) would be easiest.
>
> Another option (probably the easiest one yet) would be to run the STOMP
> library in a small external application and then communicate from that to
> NOX.  This communication could be done using Twisted, but NOX has the
> messenger/jsonmessenger components which are meant for doing this sort of
> thing and are somewhat easier.
>
> As a sidenote, being able to more easily interface with third party Python
> libraries was one of the design points for POX.
>
> -- Murphy
>
> On Jul 24, 2012, at 8:37 AM, Neha Jatav wrote:
>
> Hi,
>
> I am trying to create a listener inside the NOX script to listen to
> changes in a variable done externally. The script listener.py attached with
> this email runs fine by itself. I'm not sure where to add it in the NOX
> script because the script listener.py also needs a time.sleep() for it to
> listen indefinitely. I'd be highly obliged if you could guide me where to
> add the listener part in the NOX script. I tried to add the listener part
> to my NOX script as follows; but it didn't work. STOMP connect was setup in
> the beginning but was lost soon.
>
> # listener code starts ===================================
>
> import time
> import sys
> import os
> import stomp
> import Globals
>
> user = os.getenv("STOMP_USER") or "admin"
> password = os.getenv("STOMP_PASSWORD") or "password"
> host = os.getenv("STOMP_HOST") or "localhost"
> port = os.getenv("STOMP_PORT") or 61613
> destination = sys.argv[1:2] or ["/topic/event"]
> destination = destination[0]
>
> # listener code ends ===================================
>
> class lbtest(Component):
>
>     def install(self):
>         self.register_for_packet_in(self.packet_in_callback)
>         .......other callback functions...............
>
>     def getInterface(self):
>         return str(lbtest)
>
>     def __init__(self, ctxt):
>         Component.__init__(self, ctxt)
>         Globals.COMPONENT = self
>
> # listener code starts ===================================
>         conn = stomp.Connection(host_and_ports = [(host, port)])
>     conn.set_listener('', MyListener(conn))
>     conn.start()
>     conn.connect(login=user,passcode=password)
>     conn.subscribe(destination=destination, ack='auto')
>     Globals.log.info("Waiting for messages...")
>
> # listener code ends ===================================
>
> ......some definitions...
>
>
> # ===================================
> # Factory
> # ===================================
>
> def getFactory():
>     class Factory:
>         def instance(self, ctxt):
>             return lbtest(ctxt)
>
>     return Factory()
>
>
> # listener code starts ===================================
>
> # ===================================
> # Stomp listener for VIP change
> # ===================================
>
>
> class MyListener(object):
>
>   def __init__(self, conn):
>     self.conn = conn
>
>   def on_error(self, headers, message):
>     Globals.log.info('received an error ' + message)
>
>   def on_message(self, headers, message):
>     Globals.VIP=message
>     Globals.log.info('New VIP: '+Globals.VIP)
>
> # listener code ends ===================================
>
> Regards,
> Neha
> <listener.py>
>
>
>

Reply via email to