shunyun has asked for the wisdom of the Perl Monks concerning the following question:
I can't use alarm on Windows systems, and the Socket timeout param doesn't seem to work on udp recv (see below). Any idea of another way to do this so that I can kill the udp listener after timeout?
thx much. Shunyunsub ListenOnUDP { # Open a port my $hSocket = IO::Socket::INET->new( LocalPort=>$intListenPort, Proto=>$strProtocol ) or die "Can't create UDP socket: $@"; my ($datagram,$flags); while ($hSocket->recv($datagram,42,$flags)) { my $ripaddr = $hSocket->peerhost; my $rport = $hSocket->peerport; my $hResponseSocket = IO::Socket::INET->new( Proto=>$strProtocol, PeerHost=>$ripaddr, PeerPort=>$intSendPort ); $hResponseSocket->send("PONG!"); close($hResponseSocket); last; } close($hSocket); }
|
|---|