Ah, I realized I need to call the reference the stompClient like this &#39;self.stompClient&#39;.<br><br>Unfortunately, what is returned by this:<br><br>testq = internet.TCPClient(APPVARIABLES[&#39;queue_server&#39;], int(APPVARIABLES[&#39;queue_port&#39;]), 
connections.StompClientFactory(username=&#39;&#39;,password=&#39;&#39;,queue=&#39;/queue/test&#39;))<br><br>is the StompClientFactory object, not the StompProtocol object which contains the send() method.<br><br>So, any ideas on how I can reference the StompProtocol object (that is created by the StompClientFactory) from the GetUDP object?
<br><br>Thanks,<br><br>Don<br><br><div class="gmail_quote">On Dec 12, 2007 9:10 AM, Don Smith &lt;<a href="mailto:donwsmith@gmail.com">donwsmith@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks for your response, Christian!<br><br>However, this still does not work and I think it is related to the StompClientFactory and the StompProtocol I&#39;m using. I&#39;m including those at the end of this email so you can see what they do.
<br><br>I changed my GetUDP class to this:<div class="Ih2E3d"><br><br>class GetUDP(DatagramProtocol):<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def datagramReceived(self, datagram, address):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print datagram,address<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Send datagram to the queue server
<br></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stompclient.send(datagram)<br><br>And I changed the instantiation to what you gave me, but I get this error when I get a UDP packet:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File &quot;Agent_service_test.py&quot;, line 103, in datagramReceived
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stompclient.send(datagram)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exceptions.NameError: global name &#39;stompclient&#39; is not defined<br><br><br>Here are my stomp classes:<br><br>class StompProtocol(Protocol, stomper.Engine):<br><br>
&nbsp;&nbsp;&nbsp; def __init__(self, username=&#39;&#39;, password=&#39;&#39;, queue=&#39;&#39;):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stomper.Engine.__init__(self)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.username = username<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.password = password<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.counter = 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.log = logging.getLogger(&quot;sender&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.queue

 = queue<br><br>&nbsp;&nbsp;&nbsp; def connected(self, msg):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;Once I&#39;ve connected I want to subscribe to the message queue.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stomper.Engine.connected(self, msg)<br>

<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #self.log.info(&quot;Connected: session %s. Begining say hello.&quot; % msg[&#39;headers&#39;][&#39;session&#39;])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #lc = LoopingCall(self.send)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #lc.start(1)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f = stomper.Frame

()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f.unpack(stomper.subscribe(self.queue))<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # ActiveMQ specific headers:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # prevent the messages we send comming back to us.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f.headers[&#39;activemq.noLocal&#39;] = &#39;true&#39;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return f.pack()<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def ack(self, msg):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;Processes the received message. I don&#39;t need to <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; generate an ack message.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.log.info(&quot;SENDER - received: %s &quot; % msg[&#39;body&#39;])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return stomper.NO_REPONSE_NEEDED<br><br><br>&nbsp;&nbsp;&nbsp; def send(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;Send out a hello message periodically.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.log.info(&quot;Saying hello (%d).&quot; % self.counter)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.counter += 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f = stomper.Frame()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f.unpack(stomper.send(self.queue, &#39;hello there (%d)&#39; % 
self.counter))<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # ActiveMQ specific headers:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f.headers[&#39;persistent&#39;] = &#39;true&#39;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.write(f.pack())<br><br><br>&nbsp;&nbsp;&nbsp; def connectionMade(self):<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;Register with stomp server.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd = stomper.connect(self.username, self.password)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.write(cmd)<br><br><br>&nbsp;&nbsp;&nbsp; def dataReceived(self, data):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;Data received, react to it and respond if needed.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msg = stomper.unpack_frame(data)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; returned = self.react(msg)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if returned:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.write(returned)<br><br>class StompClientFactory(ReconnectingClientFactory):<br>&nbsp;&nbsp;&nbsp; def __init__(self, username=&#39;&#39;, password=&#39;&#39;, queue=&#39;&#39;,queue_type=&#39;&#39;,config=&#39;&#39;):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.username=username<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.password=password<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.queue=queue<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.queue_type=queue_type<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.config_file=config<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def buildProtocol(self, addr):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.queue_type ==&#39;config&#39;:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ConfigurationProtocol(self.queue,self.config_file,self.username, self.password)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return StompProtocol(self.username, 
self.password, self.queue)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def clientConnectionLost(self, connector, reason):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;Lost connection<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;Lost connection.&nbsp; Reason:&#39;, reason
<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def clientConnectionFailed(self, connector, reason):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;Connection failed<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;Connection failed. Reason:&#39;, reason&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)<div><div></div><div class="Wj3C7c"><br><br><div class="gmail_quote">On Dec 12, 2007 8:16 AM, Christian Simms &lt;<a href="mailto:christian.simms@gmail.com" target="_blank">
christian.simms@gmail.com
</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div>On Dec 12, 2007 12:08 AM, Don Smith &lt;
<a href="mailto:donwsmith@gmail.com" target="_blank">donwsmith@gmail.com</a>&gt; wrote:<br>&gt; Hi all,<br>&gt;<br>&gt; I&#39;m trying to build an app using MultiService. I need to have 2 services,<br>&gt; one that listens for UDP datagrams and another that can send those datagrams
<br>&gt; to an ActiveMQ server via a Stomp client.<br>&gt;<br>&gt; I can set up the two services just fine, but I&#39;m stuck with how to call the<br>&gt; MQ service send method from the UDPServer instance.<br>&gt;<br>&gt; Some code to illustrate:
<br>&gt;<br>&gt;<br>&gt;<br>&gt; class GetUDP(DatagramProtocol):<br>&gt;<br>&gt; &nbsp; &nbsp; def datagramReceived(self, datagram, address):<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; print datagram,address<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; #Send datagram to the queue server
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; # I don&#39;t know how to access the send method for the Stomp client<br>&gt; service!<br>&gt;<br>&gt;<br>&gt;<br>&gt; testq = internet.TCPClient(APPVARIABLES[&#39;queue_server&#39;],<br>&gt; int(APPVARIABLES[&#39;queue_port&#39;]), 
connections.StompClientFactory<br>&gt; (username=&#39;&#39;,password=&#39;&#39;,queue=&#39;/queue/test&#39;))<br>&gt; testq.setName(&#39;Testq&#39;)<br>&gt; testq.setServiceParent(MQService)<br>&gt;<br>&gt;<br>&gt; #create a UDP listener
<br>&gt; #TODO: this should be driven by the config file<br>&gt; #reactor.listenUDP(42000, GetUDP())<br>&gt; internet.UDPServer(42000,GetUDP()).setServiceParent(MQService)<br>&gt; # Create an application as normal<br>&gt; application = 
service.Application(&quot;MQExample&quot;)<br>&gt;<br>&gt; # Connect our MultiService to the application, just like a normal service.<br>&gt; MQService.setServiceParent(application)<br>&gt;<br>&gt;<br>&gt; Note: this is won&#39;t run exactly as is, but should give an idea of my
<br>&gt; problem. I&#39;ve setup the ActiveMQ Stomp client as &#39;testq&#39;. I&#39;ve setup the<br>&gt; UDPServer service to listen for UDP packets. I can get the UDP packets and<br>&gt; print them, but I can&#39;t figure out how to hand them to my Stomp client&#39;s
<br>&gt; send() method. This is possible, right?<br>&gt;<br>&gt; Thanks,<br>&gt;<br>&gt; Don<br>&gt;<br></div></div>&gt; _______________________________________________<br>&gt; Twisted-Python mailing list<br>&gt; <a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">

Twisted-Python@twistedmatrix.com</a><br>&gt; <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>&gt;<br><br>
The answer is really easy -- you don&#39;t need any twisted magic to do
<br>this, you just need to use standard Python mechanisms. &nbsp;Your UDP<br>listener, when it receives some data, just needs a Python reference to<br>your Stomp client. You could have stuffed a reference to the Stomp<br>client in a module global variable (naughty!), or better, you could
<br>have stuffed it in an attribute of your GetUDP object. So you could<br>change this line:<br><div><br> &nbsp; internet.UDPServer(42000,GetUDP()).setServiceParent(MQService)<br><br></div>to these lines:<br><br>
 &nbsp; udpService = GetUDP()<br> &nbsp; udpService.stompClient = testq &nbsp;# stuff it in!<br> &nbsp; internet.UDPServer(42000,udpService).setServiceParent(MQService)<br><br>Cheers,<br>Christian<br><br>_______________________________________________
<br>Twisted-Python mailing list<br><a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br><a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
</a><br></blockquote></div><br>
</div></div></blockquote></div><br>