iic has asked for the wisdom of the Perl Monks concerning the following question:
########################server.pl #!/usr/bin/perl $args=@ARGV; if($args!=2) { print "usage:server.pl [localport] [localfile]\n"; exit; } $port=$ARGV[0]; $file=$ARGV[1]; use IO::Socket; $skt=IO::Socket::INET->new(LocalAddr=>'0.0.0.0',LocalPort=>$port,Proto +=>'tcp',Listen=>5)||do{ print $!."\n"; exit; }; $skt->autoflush(1); print "Ready on port $port ...\n"; $newskt=$skt->accept; $newskt->sockopt(SO_SNDLOWAT,2048); $newskt->autoflush(1); print "client is coming ...\n"; open (FILE,">$file")||die $!; while($n=sysread($newskt,$buf,2)) { $total+=$n; print FILE $buf; print "received:".$total."\r"; } close FILE; $newskt->close(); $skt->close(); print "\nDone.($file)\n"; ########################client.pl #!/usr/bin/perl $args=@ARGV; if($args!=3) { print "usage:client.pl [peerhost] [peerport] [localfile]\n"; exit; } $host=$ARGV[0]; $port=$ARGV[1]; $file=$ARGV[2]; use IO::Socket; $skt=IO::Socket::INET->new(PeerAddr=>$host,PeerPort=>$port,Proto=>'tcp +')||do{ print $!."\n"; exit; }; print "Begin ...\n"; open (FILE,"$file")||die $!; binmode FILE; while($n=read(FILE,$buf,512)) { $total+=$n; print $skt $buf; print "sent:".$total."\r"; } close FILE; $skt->close(); print "\nDone.(local $file to remote $host)\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: network suspend again!
by fs (Monk) on Jun 05, 2001 at 22:01 UTC |