0
votes

I'm implementing a basic file transfer system between a client and server, for practice using UDP. I'm trying to implement some basic reliability.

Right now my server sends a chunk of data, and waits for an acknowledgement signal saying the chunk was received. Is there a way to send a more robust message without the use of signals?

Ideally I'd like to just be able to use sendto and recvfrom, but in the off chance that no packets are received, then recvfrom would just hang.

Is this possible, or do I need to use signals?

2

2 Answers

3
votes

You can use select() to learn when there's input to be read from the socket on which you receive ACKs from the client. You can then specify a timeout, after which select() will return even if no input is available. This gives you a chance to keep the server "alive".

You can also use non-blocking I/O, which gives even more flexibility, but is a bit harder since you need to take care not to "busy loop" and consume too much CPU.

1
votes

Set a socket read timeout with setsockopt() and SO_TIMEOUT.