Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Socket Timeout

341 views
Skip to first unread message

Eric Cifreo

unread,
Apr 9, 2002, 2:14:07 PM4/9/02
to
Hi all,

New to CSharp but veteran Java programmer, so this is not completely foreign
to me.

I'm dealing with a UdpClient object, and calling Receive() and it blocks by
default. Is there a way for me to set a timeout on the socket, so if
nothing responds, the block will end?

I've looked at:

Socket sock = myUdpClient.Client;

and investigated some of the underlying socket options, but the one that
comes closest is the LingerTime option. This doesn't seem right though...
Or am I just looking at the wrong place?

Thanks,

Eric Cifreo
San Marcos. TX


Nicholas Paldino [.NET/C# MVP]

unread,
Apr 9, 2002, 2:25:30 PM4/9/02
to
Eric,

What you could do is get the underlying socket (through the protected
Client property), and then call BeginReceive on that, which will notify a
delegate when the operation is complete. In the delegate, you have a flag
that is set if the information is received. In the main thread that called
BeginReceive, you have the thread wait for a specified amount of time. When
the time is up, you check to see if the asynchronous receive was performed
(by checking the flag). If it hasn't been, then you know it timed out.

Hope this helps.


--
- Nicholas Paldino [.NET MVP]
- nicholas...@exisconsulting.com

"Eric Cifreo" <eci...@austin.rr.com> wrote in message
news:PbGs8.30874$4L4.1...@typhoon.austin.rr.com...

0 new messages