Re: Strange UDP Socket problem

From: William Stacey (staceywREMOVE_at_mvps.org)
Date: 02/07/04


Date: Fri, 6 Feb 2004 20:21:30 -0500

I suspect you would get the same response if you used one thread to send and
receive. That IP likely does exist and closed the connect, you justed
picked up the exception on the other thread because your sharing the socket
(at least it looks that way.) Even if you can't ping the ip, it could still
exist, just ICMP is being blocked. Try it to a local private ip that you
know for sure does not exist. You may just want to send and receive in same
thread on same socket. Add another thread or two (each doing send/receive)
on ephemeral ports if your looking to get more sends off while waiting for
receives.

-- 
William Stacey, MVP
"Terry" <cheerio12345@hotmail.com> wrote in message
news:e$RwgnN7DHA.696@tk2msftngp13.phx.gbl...
> It's my understanding of UDP sockets that if there is a thread blocked on
a
> "recvFrom()" call and other thread sends a UDP packet to some address,
that
> if the machine on the other end isn't up, that the "recvFrom()" call
should
> just continue blocking.  Right?
>
> What I'm seeing is that when I send a packet to a particular address that
is
> not responding, my "recvFrom()" call throws an exception.  I get "An
> existing connection was forcibly closed by the remote host".  It shouldn't
> do that, right?  UDP is connectionless, so if the machine on the other end
> isn't running (well, I assume it's not running) it should just continue
> blocking right?
>
> Here's the basics of the code.  I create the socket.
> _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
> ProtocolType.Udp);
> _socket.Bind(new IPEndPoint(IPAddress.Any, 1400) );
>
> Then I spawn two threads, one for reading, one for sending:
>
> _readThread = new Thread(new ThreadStart(read) );
> _readThread.Start();
>
> _sendThread = new Thread(new ThreadStart(send) );
> _sendThread.Start();
>
> The read thread just blocks on a "recvFrom()" until it gets data (or in
this
> case throws the above exception).  The sending thread has a list of IPs it
> needs to send requests to.  It may or may not get a response to the
request.
>
> Why would I be getting a "connection closed" exception on a UDP socket?
> What am I missing in my understanding of how UDP works?
>
>
>
> Terry
>
>
>
>


Relevant Pages

  • Re: Strange UDP Socket problem
    ... You can catch that exception and move on. ... never get any udp reply back to post an exception. ... >> I suspect you would get the same response if you used one thread to send ... >> thread on same socket. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ENOSR on UDP socket creation on Solaris 10 U4
    ... response to a SOCK_DGRAM socket create? ... We're running PowerDNS recursor and are seeing occasional (once a ... the udp module, when it's asking for the capabilities of the stream. ...
    (comp.unix.solaris)
  • Re: Strange UDP Socket problem
    ... UDP packet to an IP that doesn't have anything at the other end that my ... > I suspect you would get the same response if you used one thread to send ... > thread on same socket. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Ping request UDP C# PocketPC
    ... I recently set up a UDP connection between a PC and CE device using .NET. ... Since I can't catch any exception with the ... > Socket class, which verify every x seconds if the server is available. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Ping request UDP C# PocketPC
    ... I think that send time-out is not settable on Windows CE, ... I'm not sure what a UDP send time-out would mean anyway, ... There's no such thing as a 'connected' UDP socket. ... Since I can't catch any exception with the ...
    (microsoft.public.dotnet.framework.compactframework)

Loading