[Twisted-web] Callback help client / server

Chris datarecall at hotmail.com
Wed Nov 18 03:53:21 EST 2009

from twisted.internet.protocol import Protocol, ClientFactory
from sys import stdout
from twisted.internet import reactor

from misc.configobj import ConfigObj
from misc.get_keywords import get_keywords
import time
import Queue
from bing_runner import msn
import simplejson as json
import base64
from time import sleep

class ses(object):
    def __init__(self,client):
        print "INITIATED"
        self.client = client
    def act_on(self,msg):
        print "WE GOT IT BACK"
        print msg   
    def main(self):
            print "Downloading List"

class Echo(Protocol):
    def connectionMade(self):
        print "Connected To Server"
        s = ses(self)

    def sendMessage(self, msg):
        print "Sending: %s"%msg
        d = defer.Deferred()

    def dataReceived(self, data):
        self.s.server_data = data
        return encoded

class EchoClientFactory(ClientFactory):
    protocol = Protocol
    def startedConnecting(self, connector):
        print 'Started to connect.'
    def buildProtocol(self, addr):
        print 'Connected.'
        return Echo();
    def clientConnectionLost(self, connector, reason):
        print 'Lost connection.  Reason:', reason
    def clientConnectionFailed(self, connector, reason):
        print 'Connection failed. Reason:', reason
    #def clientConnectionLost(self, connector, reason):

# this connects the protocol to a server runing on port 8000
def main():
    f = EchoClientFactory()
    f.protocol = Echo
    reactor.connectTCP("localhost", 8000, f)

# this only runs if the module was *not* imported
if __name__ == '__main__':

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
Eligible CDN College & University students can upgrade to Windows 7 before Jan 3 for only $39.99. Upgrade now!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20091118/30f282f9/attachment.htm 

More information about the Twisted-web mailing list