[Twisted-Python] How to receive a big stream data?
steven wang
steven.zdwang at gmail.com
Mon Jul 2 21:40:03 EDT 2007
========================================================
from twisted.internet import protocol, reactor, defer, interfaces
class MyProtocol(protocol.Protocol):
is_big_data = False
big_data = ''
big_data_size = 0
def connectionMade(self):
self.big_data = ''
self.big_data_size = 0
self.is_big_data = False
pass
def dataReceived(self, data):
if check_head_ok(data):
# To receive the big size data
if self.is_big_data:
return
# The big data will overflow the Twisted receive buffer size, so
loop to receive data
if self.is_big_size_data:
self.big_data += data
if self.big_data_size == len(big_data):
# To save data to database
pass
def connectionLost(self, reason):
self.big_data = ''
self.big_data_size = 0
self.is_big_data = False
pass
def check_head_ok(self, data):
if data.startswith('ABC'):
values = data.split(',')
self.big_data_size = int(values[1])
self.is_big_data = self.big_data_size > 0
return True
else:
return False
================================================================
I rewrite my source about MyProtocol. But I can not receive complete data,
only a part of data. :( Could you help me?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20070703/90e7dc25/attachment.htm
More information about the Twisted-Python
mailing list