[boulder.pm] Newbie question...
William Atkinson
CWA at DISC.com
Tue Feb 8 11:49:40 CST 2000
That's really weird. On the linux box, it works great, just like you would
expect. I cut and pasted so the code that's running is just the same as you
sent. Here's the output from the server which is still running:
[chip at wwa lab]$ ./monger.pl
Server ready. Waiting for connections. . .
Im starting a fork
Im starting a fork
Im starting a fork
Im starting a fork
>From my other window running the client:
[chip at wwa chip]$ telnet wwa 42444
Trying 192.69.46.102...
Connected to wwa.disc.com.
Escape character is '^]'.
This is being printed on Delphi.
Connection closed by foreign host.
[chip at wwa chip]$ telnet wwa 42444
Trying 192.69.46.102...
Connected to wwa.disc.com.
Escape character is '^]'.
This is being printed on Delphi.
Connection closed by foreign host.
[chip at wwa chip]$ telnet wwa 42444
Trying 192.69.46.102...
Connected to wwa.disc.com.
Escape character is '^]'.
This is being printed on Delphi.
Connection closed by foreign host.
[chip at wwa chip]$
I just checked it on an HPUX box running 5005_02 like you have and it worked
fine. I was going to try it on our Solaris box but that perl is missing the
IO/Socket.pm file. I see why you're baffled -- everything seems to work and
the code is right on at least two boxes.
Chip
> -----Original Message-----
> From: justin.crawford at cusys.edu [mailto:justin.crawford at cusys.edu]
> Sent: Tuesday, February 08, 2000 9:39 AM
> To: 'boulder-pm-list at happyfunball.pm.org'
> Subject: RE: [boulder.pm] Newbie question...
>
> 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
> >
>
More information about the Boulder-pm
mailing list