Dear all,<br><br>I&#39;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 <span style="font-weight: bold;">
buffersize.<br><span style="font-weight: bold;"><span style="font-weight: bold;"><br>The protocol description:<br><br><span style="font-weight: bold;"><span style="font-weight: bold;">First, </span>Client send data head to Server.
</span>&nbsp; Head Format:&nbsp; <span style="color: rgb(255, 0, 0);">ABC,123456,XXX,XXX,XXX^</span><br><span style="font-weight: bold;">Second, Client send big data to Server, the big data is stream data.<span style="font-weight: bold;">
<br>After Server received the big data and then save it to database.<br></span></span></span><br></span></span>My problem source code :<br>================================================================================================
<br><div style="margin-left: 40px;"><span style="color: rgb(51, 51, 255);">class MyProtocol(protocol.Protocol):</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; is_big_data = False</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; big_data = &#39;&#39;</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; big_data_size = 0</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
&nbsp;&nbsp;&nbsp; def connectionMade(self):</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.big_data = &#39;&#39;</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.big_data_size = 0</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.is_big_data = False</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pass</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; def dataReceived(self, data):</span><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;  
<br><br style="color: rgb(51, 51, 255);"></span><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; if check_head_ok(data):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: rgb(51, 51, 255);"><span style="font-style: italic; color: rgb(0, 51, 0);">
<span style="font-style: italic;"></span># To receive the big size data</span></span><br><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if </span><span style="color: rgb(51, 51, 255);">self.is_big_data:</span><span style="color: rgb(51, 51, 255);">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-style: italic; color: rgb(0, 51, 0);"></span></span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return <br style="color: rgb(51, 51, 255);">
</span><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><span style="font-style: italic; color: rgb(0, 102, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 51, 0);"># The big data will overflow the Twisted receive buffer size, so loop to receive data
</span></span><br style="color: rgb(51, 51, 255);"></span><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if is_big_size_data:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; big_data += data
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if big_data_size == len(big_data):
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # To save data to database</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ....
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pass </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span>
<span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; def connectionLost(self, reason):</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; self.big_data = &#39;&#39;</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; self.big_data_size = 0</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; self.is_big_data = False</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; def check_head_ok(self, head):</span><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;  </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; if data.startswith(&#39;ABC&#39;):</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; values = data.split(&#39;,&#39;)</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.big_data_size = int(values[1])</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.is_big_data = self.big_data_size
 &gt; 0</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return True</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; else:</span>
<br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return False&nbsp;</span>&nbsp; <br></div>================================================================================================
<br><br>If you know it, Please tell me. Thank you very much! :)<br><div style="margin-left: 40px;"><br></div><span style="font-weight: bold;"></span><br>Beat Regards,<br>Steven. Wang<br><br><br><br>