[boulder.pm] Newbie question...

Justin Crawford justin.crawford at cusys.edu
Tue Feb 8 10:38:49 CST 2000


It's running on Solaris, perl version 5005_02.  I was really surprised (because I'm not much of a coder yet) when it worked for me from the client (i.e. I got the message "This is being printed on Delphi"), but the real problem is that the script _should_ be running as a listener.  So that when the server gets a client attachment on 42444, it forks and continues listening on that port for more clients.  Instead, in my case, the server is handling only 1 connection, and then it forks, and then both parent and child exit with no errors.  And I really think it's just a problem in the way I've structured it, but I'm plumb out of ideas.

Did you find in your test that the server process printed out the "This is way to far down in the script" stuff, or did it keep waiting for connections?

Thanks!

-justin

-----Original Message-----
From:	William Atkinson [SMTP:CWA at DISC.com]
Sent:	Tuesday, February 08, 2000 9:09 AM
To:	'boulder-pm-list at happyfunball.pm.org'
Subject:	RE: [boulder.pm] Newbie question...

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
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 3927 bytes
Desc: not available
Url : http://mail.pm.org/archives/boulder-pm/attachments/20000208/d9721ed8/attachment.bin


More information about the Boulder-pm mailing list