Need/purpose... ActiveState Perl program on Win-XP to broadcast a UDP
packet (requesting info from a specific hardware device on same subnet), and
receive UDP broadcast reply from the device. The MAC address of the
specific hardware device is included in UDP data. It works.
Problem: The program works perfectly about 1/2 of the time! Sometimes it
receives the message perfectly. Sometimes it just sits indefinitely waiting
for the packet. i.e. it missed the packet. An Etherial packet capture
always shows that the hardware device DID broadcast the reply, but the Perl
code apparently didn't get it from the socket. Etherial is running on same
PC as the Perl code. The send packet always goes out ok, and the device
always replies with it's broadcast. Why does the perl code randomly miss
about half of those broadcasts that are definitely on the wire? Has anyone
had problems with this? Is there any issue with the code, or any better way
to code?
>perl -v
This is perl, v5.8.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, ...)
Code sniplet:
...
my $recv = IO::Socket::INET->new(Type => SOCK_DGRAM,
ReuseAddr => 1,
Proto => 'udp',
#Broadcast => 1,
PeerPort => '45312',
#LocalAddr =>
inet_ntoa(INADDR_BROADCAST),
LocalPort => '45313',
) || return error("unable to create recv socket: $!,$@");
my $send = IO::Socket::INET->new(Type => SOCK_DGRAM,
ReuseAddr => 1,
Proto => 'udp',
PeerAddr => inet_ntoa(INADDR_BROADCAST),
Broadcast => 1,
PeerPort => '45312',
LocalAddr => '0.0.0.0',
LocalPort => '45313',
) || return error("unable to create send socket: $!,$@");
$send->send($p) || return error("unable to send request: $!,$@");
eval {
local $SIG{ALRM} = sub { die "request timed out\n"; };
alarm(2);
if (!$recv->recv($r, 1024)) {
alarm(0);
die "error receiving response: $!,[EMAIL PROTECTED]";
}
alarm(0); 1;
};
return error($@) if ($@);
return($r);
....
This was originally written to run on a Linux machine, hence the timeout
code, which does not appear to work on the PC. When it fails, the code
appears sits at the recv, and doesn't time out on the pc. I can broadcast
another UDP message from another program, and this program will catch it ok,
even after missing the broadcast one from the hardware device. Why does it
fails sometimes and works properly sometimes?
Any thoughts or ideas would be greatly appreciated! Thanks!!
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs