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