[tpm] UDP broadcast/receive problems
James E Keenan
jkeenan at pobox.com
Fri Oct 9 19:26:03 PDT 2020
On 10/9/20 9:42 PM, Fulko Hew wrote:
>
>
> On Fri, Oct 9, 2020 at 9:06 PM James E Keenan <jkeenan at pobox.com
> <mailto:jkeenan at pobox.com>> wrote:
>
> On 10/9/20 8:41 PM, Fulko Hew wrote:
> > 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
> <http://255.255.255.255:9999> <http://255.255.255.255:9999>
> > 192.168.1.149:port <-- 192.168.1.130:9999
> <http://192.168.1.130:9999> <http://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) {
In the line above, are you trying to say, "do this 100 times"?
> > my @ready = $s->can_read(1);
> > foreach (@ready) {
> > die("readable but nothing read\n") unless
> > defined($_->recv($rsp, 1024));
What is $_ in the line above?
> > print $rsp;
> > }
> > }
> >
>
> First suggestion: use strict;
>
>
> OK, I added strict. It didn't tell me anything I didn't already know.
>
> In particular, I can't tell what you mean by $rsp
>
>
> $rsp is the receive buffer that'll contain each response to my broadcast.
>
>
More information about the toronto-pm
mailing list