I have a simple UDP socket program in C. The client transmits data to the server and receives acknowledgements. I already know how to configure a timeout so that if ‘recvfrom()’ doesn’t receive anything in a certain period of time the alarm goes off.
HOWEVER, there are a few more situations I need to handle. What if I receive a reply from an unexpected address, or the reply is not formatted correctly? I don’t want to retransmit immediately, only when the alarm goes off.
Let me know if I need to clarify.
Look into
select(2)andpoll(2)– you can wait on a socket for a specified amount of time. You can then restart the wait with lesser timeout if you need.If you are on linux, look into
epoll(7)andtimerfd_create(2).