<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
from twisted.internet.protocol import Protocol, ClientFactory<br>from sys import stdout<br>from twisted.internet import reactor<br><br>from misc.configobj import ConfigObj<br>from misc.get_keywords import get_keywords<br>import time<br>import Queue<br>from bing_runner import msn<br>import simplejson as json<br>import base64<br>from time import sleep<br><br>class ses(object):<br>&nbsp;&nbsp;&nbsp; def __init__(self,client):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "INITIATED"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.client = client<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.main()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def act_on(self,msg):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "WE GOT IT BACK"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print msg&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def main(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "Downloading List"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.client.sendMessage("get_data\r\n").addCallback(self.act_on)<br><br>class Echo(Protocol):<br>&nbsp;&nbsp;&nbsp; def connectionMade(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "Connected To Server"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = ses(self)<br><br>&nbsp;&nbsp;&nbsp; def sendMessage(self, msg):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "Sending: %s"%msg<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.write(msg)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = defer.Deferred()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep(5)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; def dataReceived(self, data):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stdout.write(data)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.s.server_data = data<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return encoded<br><br>class EchoClientFactory(ClientFactory):<br>&nbsp;&nbsp;&nbsp; protocol = Protocol<br>&nbsp;&nbsp;&nbsp; def startedConnecting(self, connector):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Started to connect.'<br>&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def buildProtocol(self, addr):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Connected.'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Echo();<br>&nbsp;&nbsp;&nbsp; def clientConnectionLost(self, connector, reason):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Lost connection.&nbsp; Reason:', reason<br>&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def clientConnectionFailed(self, connector, reason):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Connection failed. Reason:', reason<br>&nbsp;&nbsp;&nbsp; #def clientConnectionLost(self, connector, reason):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #connector.connect()<br><br># this connects the protocol to a server runing on port 8000<br>def main():<br>&nbsp;&nbsp;&nbsp; f = EchoClientFactory()<br>&nbsp;&nbsp;&nbsp; f.protocol = Echo<br>&nbsp;&nbsp;&nbsp; reactor.connectTCP("localhost", 8000, f)<br>&nbsp;&nbsp;&nbsp; reactor.run()<br><br><br># this only runs if the module was *not* imported<br>if __name__ == '__main__':<br>&nbsp;&nbsp;&nbsp; main()<br><br>I am trying to figure out a way so I can access the datareceived outside of the Echo Class so I can run operations on the data received. Fairly new to twisted. Any help is appreciated<br>                                               <br /><hr />Get Windows 7 for only $39.99-CDN College or University students only. <a href='http://go.microsoft.com/?linkid=9691814' target='_new'>This offer ends Jan 3-upgrade now!</a></body>
</html>