carloshrueda has asked for the wisdom of the Perl Monks concerning the following question:
How I do broadcast in Perl with sockets?
I have the following code:
but when executing it prints it: the network is inaccessiblesub sendbroadcast { my $msg0 = $_[0] || ''; my $port = $_[1] || ''; my ($iaddr, $proto, $thataddr, $sockaddr, $msg); return 'Error. Port empyt' unless ($port); #Conf Conn # resolve protocol, port number $remhost= '192.168.0.255'; $iaddr= inet_aton($remhost) or $msg= "No host in sendbroadcast: $! - + $GREMOTE"; return "$msg - $remhost:$port" if ($msg); $sockaddr=sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp') || 6; socket(BRFD, PF_INET, SOCK_STREAM, $proto) or $msg= "Socket in sendbr +oadcast: $!"; return "$msg - $remhost:$port" if ($msg); connect(BRFD, $sockaddr) or $msg= "connect in sendbroadcast: $!"; return "$msg - $remhost:$port" if ($msg); $msg = $msg0 . '#' x (1024 - length($msg0)); syswrite BRFD, $msg, 1024; close (BRFD); return "Sent message"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: broadcast in Perl with sockets
by sgifford (Prior) on Mar 16, 2007 at 03:55 UTC | |
|
Re: broadcast in Perl with sockets
by jesuashok (Curate) on Mar 16, 2007 at 01:32 UTC |