Given that:
The server is on windows xp running ActiveState Perl
The server is connected to an internal network and an external network
A computer on the internal network is broadcasting in udp to 10.4.255.255 on port 9722
I need to:
listen to the broadcast and pass the messages to a function
This is the code I am using:
my $sock;
do {
eval {
$sock = IO::Socket::INET->new(LocalPort => 9722, Proto => 'udp')
or die("Couldn't open the socket: $@");
1;
};
warn($@) and sleep(5) if($@);
} while ($@);
for(my $i = 0;$i < 20;$i++) {
my $string = 'a';
$sock->recv($string,1024);
print &parseInput($string);
}
note that &parseInput returns the original string it was passed.
My problem:
after calling $sock->recv(), $string becomes empty. Using another application I can see that without a doubt there is information being broadcast across 10.4.255.255, but I cannot access it.
if at all possible, I would like to remain using IO::Socket::INET.
edit: I have checked the return value of recv(..) and $!. there is no return value from recv(..) and $! = 'Unknown Error'.
edit 2: I'm trying use Socket; now and have the following:
$proto = getprotobyname('udp');
socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) or die "socket: $!";
setsockopt(SOCKET, SOL_SOCKET, SO_BROADCAST, 1) or die "sockopt: $!";
bind(SOCKET, sockaddr_in(9722, inet_aton('192.168.0.103'))) or die "bind: $!";
recv(SOCKET, $msg, 128, 0) or die "recv: $!";
It generates the error -- recv: Unknown error at ...