Click here to Skip to main content
16,015,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a simple (?) C# thread that listens on a UDP socket and returns
basic information to whoever asks for it.

I have a not-easily-repeatable error (although it recurs regularly, but
not predictably), where I get an exception because I take what I received,
process it, but when I get to the Send method, it turns out that the
IPEndpoint I got from Receive has a null (0.0.0.0) IP address.

This is for .NET 3.5.

The documentation does NOT mention this as an option, and only says that it
may throw a SocketException, which I catch, but have not seen!

The code does not "do" anything with the IPEndPoint from the time the
data is received until it sends the response.

Has anyone seen anything like this?

Or does anyone have any ideas about what would cause this?

I am running tests to try and capture it right now...

Tuesday 08/09/11 update:

I added the following code after the call to UDPClient.Receive(ref receivePoint):

C#
if (receivePoint.Address.Equals(IPAddress.Parse("0.0.0.0")))
{
    log.ErrorOut("CollectorMonitor", "Got NULL IP Address from Receive()", Constants.ERROR_RECVD_NULL_IPADDRESS);
    continue;
}


I still got the exception, but it did NOT catch the condition above! However, while the
code was in the debugger, when I did a Quick watch on the condition, it showed as true!

Now, this is a threaded application, and the other threads use TCPClient. Could there be
some type of weird interaction going on there?


Thanks,

Mitch
Posted
Updated 9-Aug-11 7:41am
v2

1 solution

I am sorry, but I never faced this, but what would you need IPEndPoint for ?
Why don't you simply use the client object returned by listner.acceptUdpClient ?
and use send method rathar than SendTo.

I am not sure I got things clear.
 
Share this answer
 
v3
Comments
mitchmcc 5-Aug-11 19:59pm    
This code is very basic. There is no listener. Once you create the UDPClient, you have to pass the IPEndPoint to the receive method so it can tell the app where the datagram came from. There are many examples of C# UDP Clients that show this technique.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900