<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:courier new,monospace"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 9, 2020 at 9:06 PM James E Keenan <<a href="mailto:jkeenan@pobox.com">jkeenan@pobox.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 10/9/20 8:41 PM, Fulko Hew wrote:<br>
> I'm trying to accomplish what I thought was easy, and yet I can't get it <br>
> to work.<br>
> <br>
> I have a number of devices that listen on UDP port 9999.<br>
> So I want to send a broadcast message to my network and see all<br>
> of their specific responses, so I can collect the list of IP addresses<br>
> (for subsequent messaging).<br>
> For a single device, it looks like this:<br>
> <br>
> 192.168.1.149:port  --> <a href="http://255.255.255.255:9999" rel="noreferrer" target="_blank">255.255.255.255:9999</a> <<a href="http://255.255.255.255:9999" rel="noreferrer" target="_blank">http://255.255.255.255:9999</a>><br>
> 192.168.1.149:port  <-- <a href="http://192.168.1.130:9999" rel="noreferrer" target="_blank">192.168.1.130:9999</a> <<a href="http://192.168.1.130:9999" rel="noreferrer" target="_blank">http://192.168.1.130:9999</a>><br>
> <br>
> So I've tried a number of things starting from a single socket all the <br>
> way to<br>
> a send socket and a second receive socket, but I can never read the <br>
> response that's sent.<br>
> <br>
> My last attempt is this code snippet... can anyone tell me what's wrong ?<br>
> <br>
> <br>
> $out = IO::Socket::INET->new(<br>
>      PeerPort  => 9999,<br>
>      PeerAddr  => inet_ntoa(INADDR_BROADCAST),<br>
>      Proto     => udp,<br>
>      ReuseAddr => 1,<br>
>      Broadcast => 1)<br>
>          or die "Can't bind : $@\n";<br>
> <br>
> my $lport = $out->sockport();           # get the local port that was <br>
> assigned<br>
> print "sending from $lport\n";<br>
> <br>
> $in = IO::Socket::INET->new(<br>
>      PeerPort  => 9999,<br>
>      LocalPort => $lport,<br>
>      Proto     => udp,<br>
>      ReuseAddr => 1)<br>
>          or die "Can't bind : $@\n";<br>
> <br>
> my $s = IO::Select->new($in);<br>
> $s->add($out);<br>
> <br>
> $out->send('hello') or die "send: $!";<br>
> <br>
> while ($i++ < 100) {<br>
>      my @ready = $s->can_read(1);<br>
>      foreach (@ready) {<br>
>          die("readable but nothing read\n") unless <br>
> defined($_->recv($rsp, 1024));<br>
>          print $rsp;<br>
>      }<br>
> }<br>
> <br>
<br>
First suggestion:  use strict;<br></blockquote><div><br></div><div style="font-family:courier new,monospace" class="gmail_default">OK, I added strict.  It didn't tell me anything I didn't already know.</div><div style="font-family:courier new,monospace" class="gmail_default"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
In particular, I can't tell what you mean by $rsp<br></blockquote><div><br></div><div style="font-family:courier new,monospace" class="gmail_default">$rsp is the receive buffer that'll contain each response to my broadcast.</div><div style="font-family:courier new,monospace" class="gmail_default"><br></div><div style="font-family:courier new,monospace" class="gmail_default"><br></div></div></div>