Reputation:
I am implementing a UDP-based Stop-and-Wait ARQ. I am trying to simulate an error probability.
In both sender and receiver, I have a while()
loop to keep sending and receiving going. Everything works until I introduce an error probability on the receiver side.
I on purpose make the receiver not send ACK
even if it has received the packet (to simulate the cases where ACK
is lost).
What surprises me is that both the sender and receiver hang! I know this because to debug I put a printf()
in both the sender's and the receiver's while
loop and nothing is printed.
Why will this happen? Even if nothing is transmitted, the while
loop (independent of sendto()
and recvfrom()
) should not stop.
Upvotes: 0
Views: 300
Reputation: 963
I think the issue is that you have recvfrom
in both the sender and receiver while loops.
The recvfrom documentation says:
If no messages are available at the socket, the receive calls wait for a message to arrive, unless the socket is nonblocking.
To make a socket nonblocking see the documentation about the MSG_DONTWAIT flag.
So, I'm guessing that when you have the receiver not send your acknowledge message, the sender is just stopping and waiting on the recvfrom function and the receiver is hanging on its own recvfrom function the 2nd time through the while loop after omitting the acknowledge message (both the sender and receiver are using the blocking function recvfrom, 1 of them needs to be sending a message).
Upvotes: 1