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: 181
        
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 ACKand thus starts transmitting the next packet;
- the sender receives an incorrect ACKand thus retransmits this packet;
- the sender receives no ACKwithin aTIMEOUTand 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 receivedACK. Since in my implementation the incorrectACKis of the same length of the correct one, so I will have to go deeper and check the contents of theACK. It's not a big deal. I know how to do.
- Problems come when I am trying to recognize scenario 3 where no ACKis received. What confuses me is that myrecvfrom()is within a while loop, so therecvfrom()will be called constantly. What will it return when the receiver is not actually sending the senderACK? Is it 0 or 1?
© Stack Overflow or respective owner