recvfrom() return values in Stop-and-Wait UDP?

Posted by mavErick on Stack Overflow See other posts from Stack Overflow or by mavErick
Published on 2013-10-22T03:38:22Z Indexed on 2013/10/22 3:53 UTC
Read the original article Hit count: 128

Filed under:
|
|

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,

  1. the sender receives a correct ACK and thus starts transmitting the next packet;
  2. the sender receives an incorrect ACK and thus retransmits this packet;
  3. 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?

© Stack Overflow or respective owner

Related posts about c

    Related posts about sockets