Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Network Programming With Perl

by princepawn (Parson)
on Sep 01, 2001 at 00:15 UTC ( [id://109531]=note: print w/replies, xml ) Need Help??


in reply to Network Programming With Perl

I used a little example in this book so that when my Net::FTPServer is down and someone FTP's to it, they get a little message saying "FTP Server is down":
#!/arudev/bin/perl use strict; use IO::Socket qw(:DEFAULT :crlf); $/ = CRLF; my ($bytes_out, $bytes_in, $quit); $SIG{INT} = sub { $quit++ }; my $port = $ENV{ARUFTPD_PORT} || die "ENV{ARUFTPD_POR} not defined"; my $sock = IO::Socket::INET->new( Listen => 20, LocalPort => $port, Timeout => 60*60, Reuse => 1 ) or die "Can't create listening socket: $!\n"; warn "waiting for incoming connection on port $port\n"; while (!$quit) { next unless my $session = $sock->accept; my $peer = gethostbyaddr($session->peeraddr,AF_INET) || $session->peerhost; my $port = $session->peerport; warn "Connection from [$peer,$port]\n"; my $msg = "230- *** SERVER IS DOWN FOR MAINTENANCE***\n"; print $session $msg; open A, '/m/aru/aruftpd/conf/aruftpd_welcome.text'; print $session "230- $_" while (<A>); print $session $msg; close $session; } close $sock;
That being said, if you have a huge networking task to do, it is much better to look at Event, ParallelForkManager, POE , or Stem to save yourself more than just time.

And a final thing about this book is the author. Lincoln Stein is a very responsive person when you have an issue with his books or software, often getting back within one hour. And what else gets me is that this guy has an MD. I mean, I have 2 degrees in Comp. Sci. and one in Computational Neuroscience and I still can't touch his expertise in Perl. Damn!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found