title: C++, UDP, sendto needs delay to work
body: <p>I am programming a UDP Relaying Server in C++. But I have a problem.</p>
  
  <p>I have a basic loop that just calls <code>recvfrom()</code>, checks for errors in the packet, then reads the "target" out of the packet and uses <code>sendto()</code> on the  same socket to send a packet to the target client that is also relaying on the same server.</p>
  
  <p>The problem is that nearly all packets get lost if I don't add a delay before the <code>sendto()</code> (this delay depends on the connection speed, so I can´t set it statically).</p>
  
  <pre><code>m_iSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  bind(m_iSocket, (SOCKADDR*)&amp;m_oSockAddress, sizeof(SOCKADDR_IN));
  ...
  while(true) {
      recvfrom(m_iSocket, (char*)m_pRecvBuffer, m_nBufferSize, 0, (SOCKADDR*)&amp;remoteAddr, &amp;remoteAddrLen);
      ...
      sendto(m_iSocket, reinterpret_cast&lt;char*&gt;(rw.getData()), rw.getBufferSize(), 0, targets address , address size);
  }
  </code></pre>
  
  <p>Any ideas?</p>