Trying with my server/client stuff.

Problem:

If I have a connect from a client, a program needs to be executed. each time when there is a connect from a client. But if the program isn't finished executing it needs to wait until it's finished and then start it...

My solution:

SERVER: #!/usr/bin/perl -w

use IO::Socket; use Net::hostent; $PORT = 9000; $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; print "[Server $0 accepting clients]\n"; while ($client = $server->accept()) { $client->autoflush(1); my $pid = fork(); if ($pid) { #parent my $hostinfo = gethostbyaddr($client->peeraddr); printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost +; print "Being Handled by child with pid $pid]\n"; wait(); } else { #child print $client "Welcome to $0.\n"; system('./sleep.pl'); } close $client; }
My executing program(just for testing):
#!/usr/bin/perl -w my $num=1; foreach(1..5) { print "PRINT: $num\n"; $num++; sleep 5; }
But there is still a problem here :( when I telnet to the server the telent session keeps hanging after being finished. Si I assume if I write a client it also keeps hanging...

--
My opinions may have changed, but not the fact that I am right


In reply to more forking troubles by toadi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.