title: recvfrom() return values in Stop-and-Wait UDP?
body: <p>I am trying to implement a <code>Stop-and-Wait UDP</code> client-server socket program in C. As known, there are basically <strong>three possible scenarios</strong> for <code>Stop-and-Wait</code> flow control. i.e., After transmitting a packet, </p>
  
  <ol>
  <li>the sender receives a correct <code>ACK</code> and thus starts transmitting the next packet;</li>
  <li>the sender receives an incorrect <code>ACK</code> and thus retransmits this packet;</li>
  <li>the sender receives no <code>ACK</code> within a <code>TIMEOUT</code> and thus retransmits this packet.</li>
  </ol>
  
  <p>My idea is to differentiate these three scenarios with the return value of <code>recvfrom()</code> on the sender side.</p>
  
  <ul>
  <li>For scenario 1&amp;2: <code>recvfrom()</code> just returns the length of the received <code>ACK</code>. Since in my implementation the incorrect <code>ACK</code> is of the same length of the correct one, so I will have to go deeper and check the contents of the <code>ACK</code>. It's not a big deal. I know how to do.</li>
  <li>Problems come when I am trying to recognize scenario 3 where no <code>ACK</code> is received. What confuses me is that my <code>recvfrom()</code> is within a while loop, so the <code>recvfrom()</code> will be called constantly. <strong>What will it return when the receiver is not actually sending the sender <code>ACK</code>? Is it 0 or 1?</strong></li>
  </ul>