Solved

C# and UDPClient error recovery

Posted on 2014-11-24
2
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

626 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