title: Read from socket: Is it guaranteed to at least get x bytes?
body: <p>I have a rare bug that seems to occur reading a socket.</p>
  
  <p>It seems, that during reading of data sometimes I get only 1-3 bytes of a data package that is bigger than this.</p>
  
  <p>As I learned from pipe-programming, there I always get at least 512 bytes as long as the sender provides enough data.</p>
  
  <p>Also my sender does at least transmit >= 4 Bytes anytime it does transmit anything -- so I was thinking that at least 4 bytes will be received at once in the beginning (!!) of the transmission.</p>
  
  <p>In 99.9% of all cases, my assumption seems to hold ... but there are really rare cases, when less than 4 bytes are received. It seems to me ridiculous, why the networking system should do this?</p>
  
  <p>Does anybody know more?</p>
  
  <p>Here is the reading-code I use:</p>
  
  <pre><code>mySock, addr = masterSock.accept()
  mySock.settimeout(10.0)
  result = mySock.recv(BUFSIZE)
  # 4 bytes are needed here ...
  ...
  # read remainder of datagram
  ...
  </code></pre>
  
  <p>The sender sends the complete datagram with one call of send.</p>
  
  <p>Edit: the whole thing is working on localhost -- so no complicated network applications (routers etc.) are involved. BUFSIZE is at least 512 and the sender sends at least 4 bytes.</p>