Solved

C# and UDPClient error recovery

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

12 Experts available now in Live!

Get 1:1 Help Now