title: Strange connection time-out using winsock
body: <p>I've been stuck debugging my custom downloader all morning now and I finally know where it goes wrong but I don't know why.</p>
  
  <p>Let me explain: I'm coding a HTTP downloader just using the basic winsock functions, not using any fancy class or framework. I don't mind if it blocks because it is already running in a separate thread so actually I just use the example code on MSDN:</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/ms737591(v=VS.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms737591(v=VS.85).aspx</a></p>
  
  <p>Sending the request:</p>
  
  <pre><code>GET /index.html HTTP/1.0\r\n
  Host: www.example.com\r\n
  User-Agent: MyCustomDownloader/1.0\r\n
  \r\n
  \r\n
  </code></pre>
  
  <p>And in the receive loop I do some allocation, parse header lines, open file handle, etc. So it does not receive all in one go, it takes some time. But I suppose that shouldn't be a problem right? I receive in blocks of 4096 bytes.</p>
  
  <p>All is fine but sometimes recv returns -1 before it returns 0. And when I call WSAGetLastError() it returns 10060 indicating:</p>
  
  <pre><code>WSAETIMEDOUT
  
  Connection timed out.
  A connection attempt failed because the connected party did not properly
  respond after a period of time, or the established connection failed 
  because the connected host has failed to respond.
  </code></pre>
  
  <p>First I thought it was the host, but I observe the behavior with any host...</p>
  
  <p>Is this normal for HTTP connections that they just drop-out from time to time? Am I doing something wrong?</p>