[Twisted-Python] how do i do that

sophismus at gmx.de sophismus at gmx.de
Tue May 5 06:39:28 EDT 2009

i'm quite new in python and twisted and did things wrong from the start now i have to reconsider my prog.
first i thought of an easier example with almost the same functionality. 
functionality: client connects, sends info, all infos from all clients are concurrently processed, a special client with the right info at the right time gets a special msg 
i got this:
it is thought that a client writes an int as birthday back...

from twisted.internet import protocol, reactor, defer, threads
days = []
allprotocols = []
class BServerProtocol(protocol.Protocol):
        birthday = 0
        def connectionMade(self):
                print "puh"
                global allprotocols
                print "allprotocols",allprotocols
        def congratulate(self):
                return 'done'
        def dataReceived(self,data):
                print data
                if int (data)>0:
                        self.birthday = int(data)
                        print "self.bday:",self.birthday
                        global days
#                       self.factory.deferred.callback("uiuiui+1")
                if data == "thanks":
                        self.write("well done")
class BServerFactory(protocol.ServerFactory):
        protocol = BServerProtocol
        def __init__(self):
                self.deferred = defer.Deferred()
def proveday():
        day = 5 #of may, think of this date as new decided 
                #from a white rabbit every time it runs
        ret = -1
        found = False
        i = 0
        length = len(allprotocols)
        while (i<length and found == False):
                birthday = allprotocols[i].birthday
                print "birthday:",birthday
                if birthday == day:
                        print 'bday==day'
                        print "allprotocols[i]:",allprotocols[i]
                        found =True
                        ret = i
        return ret
def startprove():
        r = proveday()

bsf = BServerFactory()
#commands =[(startprove,[],{})]
allprotocols[i].congratulate() should get in connection with the client again, but nothing happens, when another client connects a lot of congratulations are thrown, it seems transport buffers. i tried a lot of things, with no better result, maybe i can get some hints to get a solution...

Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01

More information about the Twisted-Python mailing list