Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# and UDPClient error recovery

Posted on 2014-11-24
2
Medium Priority
?
259 Views
Last Modified: 2014-12-11
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?

Thanks
GpsThread.cs
0
Comment
Question by:bnonnemann
2 Comments
 
LVL 16

Accepted Solution

by:
hjgode earned 2000 total points
ID: 40463860
I have done some coding with UDP broadcast client and never had such problems. But my code does not use the blocking socket.receive but  socket.BeginReceiveFrom which delgates the 'receive' to a seprate task.

Possibly my code helps you, see https://github.com/hjgode/VMusage/blob/master/VMusageRecvr/sockrcv.cs
0
 

Author Closing Comment

by:bnonnemann
ID: 40494741
It appears the broadcasting device was having some issues, however for the nice code provided I'll accept as answer
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Loops Section Overview

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question