Re: Strange UDP Socket problem
From: William Stacey (staceywREMOVE_at_mvps.org)
Date: 02/07/04
- Next message: Rob Teixeira [MVP]: "Re: What DirectX SDK Version for VC#.NET 2002?"
- Previous message: nick: "Re: extendeddatagridcomboboxcolumn"
- In reply to: Terry: "Re: Strange UDP Socket problem"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 7 Feb 2004 02:04:41 -0500
I did some testing on this and its does not have to do with the threads.
You get the same error sending and receiving to an IP that exists, but is
not listening on that port. If the IP does not exist then it blocks forever
or until timeout. Guess that makes sense. You don't get an error until you
actually try to read something. You can catch that exception and move on.
You know the IP is alive, but nothing is listening on that port or is forced
down. If you could not reach the IP at all, it would block waiting as you
never get any udp reply back to post an exception.
HTH
-- William Stacey, MVP "Terry" <cheerio12345@hotmail.com> wrote in message news:e#Idy2T7DHA.3704@tk2msftngp13.phx.gbl... > I guess I was just expecting different behavior. I figured that if I send a > UDP packet to an IP that doesn't have anything at the other end that my > "recvFrom()" call would just block forever waiting for something to come > back. > > Hmm. Maybe I can't do what I'm trying to do. I have a list of IP's that I > need to send an identical packet to and time the round-trip time. I thought > I could just have one thread just cycling through the IPs sending the > datagram, and having another thread to just read the responses as they come > in. > > So, are you saying that I won't be able to do another "sendTo()" until the > response has been received or I get a WSAECONNRESET indicating there's > nothing at the other end? > > > "William Stacey" <staceywREMOVE@mvps.org> wrote in message > news:#oLoCjR7DHA.1428@TK2MSFTNGP12.phx.gbl... > > 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 > > > > > > > > > > > > > > > > > >
- Next message: Rob Teixeira [MVP]: "Re: What DirectX SDK Version for VC#.NET 2002?"
- Previous message: nick: "Re: extendeddatagridcomboboxcolumn"
- In reply to: Terry: "Re: Strange UDP Socket problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|