Re: Strange UDP Socket problem
From: William Stacey (staceywREMOVE_at_mvps.org)
Date: 02/07/04
- Next message: DalePres: "Re: sending message to app on other computer"
- Previous message: Sput: "sending message to app on other computer"
- In reply to: Terry: "Strange UDP Socket problem"
- Next in thread: Terry: "Re: Strange UDP Socket problem"
- Reply: Terry: "Re: Strange UDP Socket problem"
- Messages sorted by: [ date ] [ thread ]
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 > > > >
- Next message: DalePres: "Re: sending message to app on other computer"
- Previous message: Sput: "sending message to app on other computer"
- In reply to: Terry: "Strange UDP Socket problem"
- Next in thread: Terry: "Re: Strange UDP Socket problem"
- Reply: Terry: "Re: Strange UDP Socket problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading