Thanks for the reply, all. I searched through the threads you referenced and saw good examples of setting non-blocking mode. I'm not sure I'm using this right, tho. If I place the statement after establishing the socket and before the while statement (while recv), the receive evaluates false and the while statement doesn't execute.

my $hSocket = IO::Socket::INET->new( LocalPort=>$intListenPort, Proto=>$strProtocol ) or die "Can't create UDP socket: $@"; ioctl($hSocket, 0x8004667e, pack("I", 1)); my ($datagram,$flags); # Wait for a datagram, then open a response port, respond, then close both ports. while ($hSocket->recv($datagram,42,$flags)) { ...
So, I'm wondering if this is the right approach. I think the core of the problem is that I'm waiting for incoming data to determine if a connection has been established.

Is there another way to watch for client connection (and corresponding technique to time-out), before establishing the recv loop? For instance, doesn't IO::Socket call an accept method on connection? So couldn't I check $hSocket for a value (undef?) until timeout, and then launch the recv loop once I have a client? Or maybe using the accept method directly, like

until ($hSocket->accept()) { ...check for timeout ...close socket and exit if timeout } while ($hSocket->recv($datagram,42,$flags)) { ...

I guess I'm asking if blocking is really the problem or my approach to checking for connection. I think...


In reply to Re^2: Timeout Socket recv on UDP... on windows by shunyun
in thread Timeout Socket recv on UDP... on windows by shunyun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.