title: Python dectect the length of the data with socket
body: <p>I found this code to detect the length of encrypted data in the frame :</p>
  
  <pre><code>header = self.request.recv(5)
  if header == '':
     #print 'client disconnected'
     running = False
     break
  (content_type, version, length) = struct.unpack('&gt;BHH', header)
  data = self.request.recv(length)
  </code></pre>
  
  <p>Souce : </p>
  
  <ul>
  <li><a href="https://github.com/EiNSTeiN-/poodle/blob/master/samples/poodle-sample-1.py" rel="nofollow">https://github.com/EiNSTeiN-/poodle/blob/master/samples/poodle-sample-1.py</a></li>
  <li><a href="https://gist.github.com/takeshixx/10107280" rel="nofollow">https://gist.github.com/takeshixx/10107280</a></li>
  <li><a href="https://gist.github.com/ixs/10116537" rel="nofollow">https://gist.github.com/ixs/10116537</a></li>
  </ul>
  
  <p>This code, listen the connection between a client and a server. When the client talk to the server, <code>self.request.recv(5)</code>  can get you the length of the header in the frame. Then we use that length to take the data.</p>
  
  <p>If we print the exchange between the client and the server :</p>
  
  <pre><code>Client  --&gt; [proxy] -----&gt; Server
  length : 24 #why 24 ?
  Client  --&gt; [proxy] -----&gt; Server
  length: 80 #length of the data
  Client  &lt;-- [proxy] &lt;----- Server
  </code></pre>
  
  <p>We can see that the client will send two packet to the server.
  If i change </p>
  
  <pre><code>data = self.request.recv(length)
  </code></pre>
  
  <p>to </p>
  
  <pre><code>data = self.request.recv(4096)
  </code></pre>
  
  <p>Only one exchange is made.</p>
  
  <pre><code>Client  --&gt; [proxy] -----&gt; Server
  length: 109 #length of the data + the header
  Client  &lt;-- [proxy] &lt;----- Server
  </code></pre>
  
  <p>My question is why we only need to take a size of 5 to get the lenght, content_type informations ? Is there an understandable doc about this ?</p>
  
  <p>Why there is two request: one with 24 and another with the lenght of our data ? </p>