Hi Murphy, Thanks for the prompt response.
Here's what I'm trying to implement: There should be a listener that constantly listens on some channel for a message. This listener should be listening constantly along with the callback functions and the function defining action on a packet arriving at the controller. Now, threading isn't possible along with NOX (as you said before). Creating a callback function to listen periodically wouldn't be prompt. If I use a blocking receive of the messenger, I will still need a while loop so that I can receive multiple such messages. So, even if I use the messenger, I'll need a separate thread which isn't possible with NOX. Can you please suggest a less complex way that might achieve the constant listening or anything close? Regards, Neha On Sat, Jul 28, 2012 at 1:40 AM, Murphy McCauley <[email protected]>wrote: > It looks like maybe I never merged my latest Python messenger code. It's > here: > http://www.noxathome.org/x/Murphy/messenger/messenger.zip > > .. and there should be some discussion of using it in the nox-dev archive > (check the Google Group). > > Hope that helps. > > -- Murphy > > > On Jul 27, 2012, at 1:03 PM, Neha Jatav wrote: > > 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> >> >> >> > >
