Hi all,i have a following code but it doesn't run :
#!/usr/bin/perl
use IO::Socket;
use IO::Select;
my $addr='210.245.87.255';
my $port=shift ||getservbyname('echo','udp');
my $socket=IO::Socket::INET->new(Proto=>'udp') or die $@;
$socket->sockopt(SO_BROADCAST()=>1) or die "sockopt:$!";
my $dest=sockaddr_in($port,inet_aton($addr));
my $select=IO::Select->new($socket,\*STDIN);
while(1){
my @ready=$select->can_read;
foreach (@ready){
do_stdin() if $_ eq \*STDIN;
do_socket() if $_ eq $socket;
}
}
sub do_stdin{
my $data;
sysread(STDIN,$data,1024)||exit 0;
send($socket,$data,0,$dest) or die "send():$!";
}
sub do_socket{
my $data;
my $addr=recv($socket,$data,.1024,0) or die"recv():$!";
my ($port,$peer)=sockaddr_in($addr);
my $host=inet_ntoa($peer);
print "received",length($data),"byte from $host:$port\n";
}
Please tell me why?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.