Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How Do I Do an IP Broadcast in Perl?

by bingos (Vicar)
on Sep 26, 2010 at 18:52 UTC ( #862111=note: print w/ replies, xml ) Need Help??


in reply to How Do I Do an IP Broadcast in Perl?

You cannot broadcast using TCP. You will have to use UDP


Comment on Re: How Do I Do an IP Broadcast in Perl?
Re^2: How Do I Do an IP Broadcast in Perl?
by HalNineThousand (Beadle) on Sep 26, 2010 at 19:21 UTC

    I changed the protocol to UDP in the broadcast program and it ran and didn't give me an error or anything. But then when I changed the protocol on the listener to UDP, it kept crashing. I removed the "Listen => 1" and it would run but do nothing.

    Here's the code for the listener:

    use IO::Socket; my $sock = new IO::Socket::INET ( LocalHost => '172.16.7.101', LocalPort => '7070', Proto => 'udp', # Listen => 1, Reuse => 1, 8 ); die "Could not create socket: $!\n" unless $sock; my $new_sock = $sock->accept(); while(<$new_sock>) { print $_; } close($sock);

    So I take it I need to change something to be able to listen on a UDP socket?

      Okay, I did more searching and found examples that did not specify the local IP address for the socket using UDP. I removed "LocalHost => '172.16.7.101'" and now it's working fine. I've even tested it with several boxes listening and they all got the same message, so I know it's actually broadcasting.

      Thanks for the help!

      Sockets are bi-directional, so they can all listen for packets. "Listen" tells IO::Socket to listen for incoming connections. UDP is connection-less, so Listen is never used with UDP.

      You have a stray "8" in your argument list.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://862111]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2015-07-07 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls