xarex has asked for the wisdom of the Perl Monks concerning the following question:
Basically all it does is listen for conections on a certain port number, and then writes the data recieved to a log file,#!/usr/bin/perl use warnings; use strict; #!/usr/bin/perl use warnings; use strict; use IO::Socket; $| = 1; my $port = 7777; my $server = IO::Socket ->new( Domain => PF_INET, LocalPort => $port, Proto => 'tcp', Listen => SOMAXCONN, Reuse => 1, ); die "Bind failed: $!\n" unless $server; #tell OS to clean up dead children $SIG{CHILD} = 'IGNORE'; print "Multiplex server running on port $port...\n"; while(my $connection = $server->accept){ my $name = $connection->peerhost; my $port = $connection->peerport; if (my $pid = fork){ close $connection; next; # on to the next connection }else{ # child process - handle connection print $connection "You're connected to the server!\n"; while (<$connection>){ use HTTP::Date; my ($date, $time) = split(" ", HTTP::Date::time2iso()); my ($hour, $min) = split(":", $time); my $log; open ($log, '+>>',"logs/$port $date.txt") || die "Couldn't op +en log.txt: $!"; print $log $_; close $log; my $dir = "logs"; my $file = "logs/$port $date.txt"; chmod (0777, $file); chmod (0777, $dir); } $connection->shutdown(SHUT_RDWR); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How Can I Reliably Cleanup Sockets in a Backgrounded Program?
by jasonk (Parson) on Jul 02, 2007 at 15:43 UTC | |
|
Re: How Can I Reliably Cleanup Sockets in a Backgrounded Program?
by Moron (Curate) on Jul 02, 2007 at 13:20 UTC | |
by xarex (Initiate) on Jul 02, 2007 at 13:35 UTC | |
by garu (Scribe) on Jul 02, 2007 at 15:25 UTC | |
by Moron (Curate) on Jul 03, 2007 at 11:42 UTC | |
|
Re: How Can I Reliably Cleanup Sockets in a Backgrounded Program?
by chrism01 (Friar) on Jul 03, 2007 at 00:42 UTC |