Re: Strange UDP Socket problem
From: Terry (cheerio12345_at_hotmail.com)
Date: 02/07/04
- Next message: Bret Pehrson: "Re: Font Question"
- Previous message: Jay B. Harlow [MVP - Outlook]: "Re: Multiple inheritance"
- In reply to: William Stacey: "Re: Strange UDP Socket problem"
- Next in thread: William Stacey: "Re: Strange UDP Socket problem"
- Reply: William Stacey: "Re: Strange UDP Socket problem"
- Reply: William Stacey: "Re: Strange UDP Socket problem"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 6 Feb 2004 23:46:19 -0600
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: Bret Pehrson: "Re: Font Question"
- Previous message: Jay B. Harlow [MVP - Outlook]: "Re: Multiple inheritance"
- In reply to: William Stacey: "Re: Strange UDP Socket problem"
- Next in thread: William Stacey: "Re: Strange UDP Socket problem"
- Reply: William Stacey: "Re: Strange UDP Socket problem"
- Reply: William Stacey: "Re: Strange UDP Socket problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|