in reply to Check for request from UDP client

Two words: "Non-blocking sockets". The problem is that your program stalls on the recv command, waiting for data. If there is no data, it will wait until the end of time for data to arrive.

So, tell your Socket to be non-blocking using:
$sock->blocking(0);
Then it will return right away, even if it didn't read anything.

Replies are listed 'Best First'.
Re: Re: Check for request from UDP client
by Anonymous Monk on Jul 05, 2001 at 21:55 UTC

    Really, it's that easy to stop blocking? Everything I've read about non-blocking talks about using select.

    So I would put this line right after getting the new object?

    $sock = IO::Socket::INET->new(etc.); $sock->blocking(0);

    Thanks for the help.

    jgentry@swcp.com

      Yes, you can use select() as well, which is a more traditional way, since with one call you can check on a large number of sockets simultaneously. If you want to use this, which isn't a bad idea, you might as well use IO::Select instead of the regular one, seeing as how you are using IO::Socket. See the documentation page by clicking on that link, as it contains a useful example.

        I only need to check one socket, so I think I'll try the short, simple method you suggested first. Thanks again for the help.

        jgentry@swcp.com