my $hSocket = IO::Socket::INET->new( LocalPort=>$intListenPort, Proto=>$strProtocol ) or die "Can't create UDP socket: $@"; ioctl($hSocket, 0x8004667e, pack("I", 1)); my( $gotone, $datagram, $flags) = 0; my $endtime = time() + $timeout; while( time() < $endtime ) { sleep 1 and next unless $hSocket->recv($datagram,42,$flags ); ## Got a datagram. ... $gotone = 1; last; } if( $gotone ) { ## We processed a datagram within the timelimit } else { ## we didn't }