On Mar 5, 2004, at 2:21 PM, Paul Kraus wrote:

I hate to ask for code but I am kind of in a crunch to finish a project.

I have the network programming with perl but it's just too much to read by
tomorrow night :)

Here's an example server, pretty much right out of the Perl Cookbook:


#!/usr/bin/perl

use strict;
use warnings;

use IO::Socket::INET;
use POSIX qw(:sys_wait_h);

my $listener = IO::Socket::INET->new( LocalPort      => 61676,
                                                                          Listen        
=> SOMAXCONN,
                                                                          Reuse         
=> 1 );

# clean up dead processed
sub REAPER {
        1 until (-1 == waitpid(-1, WNOHANG));
        $SIG{CHLD} = \&REAPER;
}
$SIG{CHLD} = \&REAPER;

while (my $socket = $listener->accept) {
        next unless $socket;

        next if my $pid = fork;
        die "Fork error:  $!" unless defined $pid;
        
        # in child here
        $listener->close();
        
        # do work here, like:
        while (<$socket>) { print; }              # or whatever
        
        exit;
}
continue {
        $socket->close();
}

__END__

Hope that gets you going.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to