<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 10:26 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 9:42 PM, Fulko Hew wrote:<br>
> <br>
> <br>
> On Fri, Oct 9, 2020 at 9:06 PM James E Keenan <<a href="mailto:jkeenan@pobox.com" target="_blank">jkeenan@pobox.com</a> <br>
> <mailto:<a href="mailto:jkeenan@pobox.com" target="_blank">jkeenan@pobox.com</a>>> wrote:<br>
> <br>
>     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<br>
>     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<br>
>     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><br>
>     <<a href="http://255.255.255.255:9999" rel="noreferrer" target="_blank">http://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><br>
>     <<a href="http://192.168.1.130:9999" rel="noreferrer" target="_blank">http://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<br>
>     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<br>
>     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<br>
>     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>
<br>
In the line above, are you trying to say, "do this 100 times"?<br></blockquote><div> </div><div><span class="gmail_default" style="font-family:courier new,monospace">Yes, although the foreach loop below allows me</span></div><div><span class="gmail_default" style="font-family:courier new,monospace">to scan and process all of the messages on each socket</span></div><div><span class="gmail_default" style="font-family:courier new,monospace">that 'currently' have messages to read... the while loop allows me to</span></div><div><span class="gmail_default" style="font-family:courier new,monospace"> look for stuff a number of times, in case messages come in later.<br></span></div><div><span class="gmail_default" style="font-family:courier new,monospace">(the 1 in the can_read() signifies a one second timeout, so the</span></div><div><span class="gmail_default" style="font-family:courier new,monospace">100 loops in the while() allows me to listen and process responses</span></div><div style="font-family:courier new,monospace" class="gmail_default"><span class="gmail_default" style="font-family:courier new,monospace">that can arrive up to 100 seconds later.)  Don't obsess about the</span></div><div style="font-family:courier new,monospace" class="gmail_default"><span class="gmail_default" style="font-family:courier new,monospace">timeouts, it's just mainly for debugging purposes.</span></div><div style="font-family:courier new,monospace" class="gmail_default"><span class="gmail_default" style="font-family:courier new,monospace"><br></span></div><div style="font-family:courier new,monospace" class="gmail_default"><span class="gmail_default" style="font-family:courier new,monospace">Anyway, and my followup says, I now have to deal with the firewall config issue.<br></span></div><div style="font-family:courier new,monospace" class="gmail_default"><span class="gmail_default" style="font-family:courier new,monospace"></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
>      >      my @ready = $s->can_read(1);<br>
>      >      foreach (@ready) {<br>
>      >          die("readable but nothing read\n") unless<br>
>      > defined($_->recv($rsp, 1024));<br>
<br>
What is $_ in the line above?<br></blockquote><div><br></div><div style="font-family:courier new,monospace" class="gmail_default">The next socket, from the list of sockets that have stuff awaiting to be read.</div><div style="font-family:courier new,monospace" class="gmail_default"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
>      >          print $rsp;<br>
>      >      }<br>
>      > }<br>
>      ><br>
> <br>
>     First suggestion:  use strict;<br>
> <br>
> <br>
> OK, I added strict.  It didn't tell me anything I didn't already know.<br>
> <br>
>     In particular, I can't tell what you mean by $rsp<br>
> <br>
> <br>
> $rsp is the receive buffer that'll contain each response to my broadcast.<br>
> <br>
> <br>
<br>
</blockquote></div></div>