Dear all,

I'm using the Twisted to write a socket server. I has a problem in the socket server. I could not receive a big size data when the data size is bigger then the connection buffersize.

The protocol description:

First, Client send data head to Server.   Head Format:  ABC,123456,XXX,XXX,XXX^
Second, Client send big data to Server, the big data is stream data.
After Server received the big data and then save it to database.

My problem source code :
================================================================================================
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 is_big_size_data:
                big_data += data
               
                if 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, head):        
          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  
================================================================================================

If you know it, Please tell me. Thank you very much! :)


Beat Regards,
Steven. Wang