title: UDP send() to localhost under Winsock throwing away packets?
body: <p>Scenario is rather simple... not allowed to use "<code>sendto()</code>" so using "<code>send()</code>" instead...</p>
  
  <p>Under <code>winsock2.2</code>, normal operation on an brand new i7 machine running  <code>Windows 7 Professional</code>...</p>
  
  <p>Using <code>SOCK_DGRAM</code> socket, Client and Server console applications connect over <code>localhost</code> (<code>127.0.0.1</code>) to test things ...</p>
  
  <p>Have to use packets of constant size...</p>
  
  <p>Client socket uses <code>connect()</code>, Server socket uses <code>bind()</code>...</p>
  
  <p>Client sends N packets using series of <code>BLOCKING</code> <code>send()</code> calls. Server only uses <code>ioctlsocket</code> call with <code>FIONREAD</code>, running in a <code>while</code> loop to constantly <code>printf()</code> number of bytes awaiting to be received...</p>
  
  <p><strong>PACKETS GET LOST UNLESS I PUT <code>SLEEP()</code> WITH CONSIDERABLE AMMOUNT OF  TIME...</strong> <em>What I mean is the number of bytes on the receiving socket differs  between runs if I do not use <code>SLEEP()</code>...</em></p>
  
  <p>Have played with changing buffer sizes, situation did not change much, except now there is no overflow, but the problem with the delay remains the same ...</p>
  
  <p>I have seen many discussions about the issue between <code>send()</code> and <code>recv()</code>, but in this scenario, <code>recv()</code> is not even involved...</p>
  
  <p>Thoughts anyone?</p>
  
  <hr>
  
  <p>(P.S. The constraints under which I am programming are required for reasons beyond my control, so no <code>WSA</code>, <code>.NET</code>, <code>MFC</code>, <code>STL</code>, <code>BOOST</code>, <code>QT</code> or other stuff)</p>
  
  <hr>
  
  <p>It is NOT an issue of buffer overflow for three reasons:</p>
  
  <ol>
  <li>Both incoming and outgoing buffers are set and checked to be
  significantly larger than ALL of the information being sent. 
  
  <ol start="2">
  <li>There is no <code>recv()</code>, only checking of the incoming buffer via <code>ioctl()</code> call, recv() is called long after, upon user input. </li>
  <li>When <code>Sleep()</code> of <code>&gt;40ms</code> is added between <code>send()</code>-s, the whole thing works, i.e. if there was an overflow no ammount of
  <code>Sleep()</code> would have helped (<code>again, see point (2)</code> )</li>
  </ol></li>
  </ol>