[tpm] UDP broadcast/receive problems
Fulko Hew
fulko.hew at gmail.com
Fri Oct 9 17:41:46 PDT 2020
I'm trying to accomplish what I thought was easy, and yet I can't get it to
work.
I have a number of devices that listen on UDP port 9999.
So I want to send a broadcast message to my network and see all
of their specific responses, so I can collect the list of IP addresses
(for subsequent messaging).
For a single device, it looks like this:
192.168.1.149:port --> 255.255.255.255:9999
192.168.1.149:port <-- 192.168.1.130:9999
So I've tried a number of things starting from a single socket all the way
to
a send socket and a second receive socket, but I can never read the
response that's sent.
My last attempt is this code snippet... can anyone tell me what's wrong ?
$out = IO::Socket::INET->new(
PeerPort => 9999,
PeerAddr => inet_ntoa(INADDR_BROADCAST),
Proto => udp,
ReuseAddr => 1,
Broadcast => 1)
or die "Can't bind : $@\n";
my $lport = $out->sockport(); # get the local port that was
assigned
print "sending from $lport\n";
$in = IO::Socket::INET->new(
PeerPort => 9999,
LocalPort => $lport,
Proto => udp,
ReuseAddr => 1)
or die "Can't bind : $@\n";
my $s = IO::Select->new($in);
$s->add($out);
$out->send('hello') or die "send: $!";
while ($i++ < 100) {
my @ready = $s->can_read(1);
foreach (@ready) {
die("readable but nothing read\n") unless defined($_->recv($rsp,
1024));
print $rsp;
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20201009/c38887b0/attachment.html>
More information about the toronto-pm
mailing list