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!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.