-
September 17th, 2008, 12:55 PM
#1
UdpClient.BeginReceive gives socket error 10054
I'm using udp at the moment, and every now and again the UdpClient i'm using decides to throw a socket exception with error code 10054. Google tells me this:
Socket error 10054 may be the result of the remote server or some other piece of network equipment forcibly closing or resetting the connection
But this is UDP. There is no connection. What exactly is causing this, and how exactly can i avoid it? My temporary fix is to dispose the existing udpclient and instantiate another one, but that seems a bit stupid. The offending code is here:
Code:
private void EndReceive(IAsyncResult result)
{
try
{
IPEndPoint e = new IPEndPoint(IPAddress.Any, endpoint.Port);
byte[] buffer = client.EndReceive(result, ref e);
// Fire the event to indicate i've received a message
if (MessageReceived != null)
MessageReceived(buffer, e);
}
catch
{
// ignore
}
// This is the part which throws an exception randomly
client.BeginReceive(EndReceive, null);
}
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|