Solved

C# and UDPClient error recovery

Posted on 2014-11-24
2
185 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help on C# Linq query on object 6 53
Question about consuming GB from Comcast 5 38
C# Single Form 8 29
What namespace do I need to import? 2 14
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now