[Twisted-Python] how do i do that
sophismus at gmx.de
sophismus at gmx.de
Tue May 5 04:39:28 MDT 2009
hey,
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
allprotocols.append(self)
print "allprotocols",allprotocols
def congratulate(self):
self.transport.write("congratulations")
return 'done'
def dataReceived(self,data):
print data
if int (data)>0:
self.birthday = int(data)
print "self.bday:",self.birthday
global days
days.append(int(data))
self.transport.write("pff")
# 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
allprotocols[i].congratulate()
i+=1
return ret
def startprove():
r = proveday()
bsf = BServerFactory()
#bsf.deferred.addCallback(registerSuccess)
reactor.listenTCP(55555,bsf)
reactor.callInThread(startprove)
#commands =[(startprove,[],{})]
#commands.append(startcong)#,[],{})
#threads.callMultipleInThread(commands)
reactor.run()
_______________________
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...
thx
stefan
--
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