CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Help needed


the Mog
New User

Jul 2, 2007, 9:08 AM

Post #1 of 2 (194 views)
Help needed Can't Post

Hi Guys,

i have the following......

#!/usr/bin/perluse 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

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
# 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 open log.txt: $!";
print $log $_;
close $log;
my $dir = "logs";
my $file = "logs/$port $date.txt";
chmod (0777, $file);
chmod (0777, $dir);


Basically all it does is listen for conections on a certain port number, and then writes the data recieved to a log file,
the above code works 100% for what i need,
My problem is if i start the script using Putty SSH like so ./
then its all fine, it creates the connections and if the connection is terninated it cleans up the dead children from the server, and releases the port again,
however, if i start the script like so
nohup ./
then it doesnt cleen up the dead children and keeps the port also in use after the host has disconnected
I need this file to be running all the time, could someone please tell me the correct way of doing this, or is there a problem in my script somewhere?

Please guys i really need to try and get this fixed



Jul 2, 2007, 11:09 AM

Post #2 of 2 (191 views)
Re: [the Mog] Help needed [In reply to] Can't Post

If nobody here answers (which will probably be the case), try the perl forum on devshed:

there are many more active members in that perl and some with a lot of experience beyond perl.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives