Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that opens several UDP sockets and reads the broadcasts. The update rates are horrendously high and unfortunately it would appear that when the rates exceed a certain level the script fails. The script looks like it is continually rereading the same block. Any thoughts?

To give an idea what the script does:

$socks[0] = IO::Socket::INET->new(LocalAddr => "10.153.22.0", LocalPort => 0x8320, Broadcast => 1, Proto => 'udp' ) or die "Can't bind\n"; $socks[1] = IO::Socket::INET->new(LocalAddr => "10.153.22.0", LocalPort => 0x8321, Broadcast => 1, Proto => 'udp' ) or die "Can't bind\n"; foreach $socket (@socks) { $socketSet->add($socket); } while ( @ready = $socketSet->can_read ) { foreach $fh ( @ready ) { $fh->recv($buf,1500); # I've tried a sysread as well # do something with it; print "$buf\n"; } }

Replies are listed 'Best First'.
Re: socket read problem
by Fletch (Bishop) on Feb 22, 2008 at 16:46 UTC

    Might be prudent to clear out your buffer variable before reading, as well as checking the return value from your recv and see if that's producing an error.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.