Solved

C# and UDPClient error recovery

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 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