I have been tasked with writing a service that logs UDP messages broadcasts from a GPS unit. I have gotten the core code working in a thread, however after doing a bit of searching, I as unsure as to best practices for handling timeouts or other errors. In the attached code, an exception is caught. This may occasionally happen following a time-out, but recovering from this condition has proven a bit hit or mostly miss. My simplistic approach for testing so far has been to unplug the GPS unit's network cable from the hub, wait 15 seconds or so, and reconnect. About 95% of the time, after the first timeout, all subsequent passes through the loop timeout, even after reconnecting the GPS. I don't think it is the GPS, as if I restart the service, it picks up just fine.
So my question basically is:
1. What is the correct way to resume listening after a timeout? Does anything need to be done? Close the client and create new one? Something else?
2. Are there any other types of socket-type exceptions that could get thrown, and should the error handling be different?
3. Should there be any additional parameters changed or programming done on the client or underlying socket for robust operation?