[boulder.pm] Newbie question...

William Atkinson CWA at DISC.com
Tue Feb 8 10:08:35 CST 2000


Well I'll take a crack at a partial answer.  Are you trying to run this
script on a Windows machine?  I ran it on a linux box and it worked just
fine.  I was able to telnet into port 42444 and got the message.  I ran it
on my nt box and got the message that fork is an unsupported function.
Depending on whose and which version of perl, that may be the problem.

Chip

> -----Original Message-----
> From: Justin Crawford [mailto:justin.crawford at cusys.edu]
> Sent: Tuesday, February 08, 2000 8:01 AM
> To: 'boulder-pm-list at happyfunball.pm.org'
> Subject: [boulder.pm] Newbie question...
> 
> 
> Hi, I'm new to the list and not sure that I qualify as a 
> Monger yet.  In any event, I've got a script question maybe 
> someone can help with....
> 
> Trying to make a basic server program using IO::Socket.  I 
> copied the whole script from a 'how-to' in a perl magazine.  
> First, here is the output (assuming a successful client 
> connection) on the server:
> 
> AspDev/____> server
> Server ready.  Waiting for connections. . .
> Im starting a fork
> Im too far down in the script!!
> Im WAY too far down now!!
> 
> Next, the script:
> 
> AspDev/____> cat server
> #!/usr/local/bin/perl -w
> use strict;
> use IO::Socket;
> use POSIX 'WNOHANG';
> 
> use constant PORT => 42444;
> 
> $SIG{CHLD} = sub { while ( waitpid (-1, WNOHANG) > 0 ) { } };
> 
> my $listen_socket = IO::Socket::INET->new(LocalPort => PORT,
>                                           Listen => 20,
>                                           Proto => 'tcp',
>                                           Reuse => 1);
> 
> die "Can't create a listening socket: $@" unless $listen_socket;
> warn "Server ready.  Waiting for connections. . .\n";
> 
> 
> while (my $connection = $listen_socket->accept) {
>    print "Im starting a fork\n";
>    die "Can't fork: $!" unless defined (my $child = fork());
>    if ($child == 0) {
>       $listen_socket->close;
>       interact($connection);
>       exit 0;
>    }
> }
> continue {
>    $connection->close;
> }
> 
> print "Im too far down in the script!!\n";
> 
> sub interact {
>    my $sock = shift(@_);
>    print $sock "This is being printed on Delphi.\n";
> }
> 
> print "Im WAY too far down now!!\n";
> 
> 
> 
> The question, of course, is why is the script only passing 
> through the while-loop once?  Thanks a lot for reading!
> 
> -justin
> 
> 
> Justin Crawford
> Oracle DBA Group
> University Management Systems
> (303) 492-9083
> justin.crawford at cusys.edu
> 



More information about the Boulder-pm mailing list