Hi there! i am trying to build a server, with multiple processes, for each client a child. So far everything works fine, but as these processes have to communicate i searched and found that FIFOs may be useful for that. So i used them and its working, but somehow it isnt.. the problem is the data from the client isnt received somehow. Below is the code for it, maybe someone can tell me why the data from the client isnt printed out by the parent (just testing for now) Thanks for help Code:
#!/usr/bin/perl -w use strict; use IO::Socket; $| = 1; #get the port to bind to or default to 8000 my $port = $ARGV[0] || 8000; #ignore child processes to prevent zombies $SIG{CHLD} = 'IGNORE'; #create the listen socket my $listen_socket = IO::Socket::INET->new(LocalPort => $port, Listen => 10, Proto => 'tcp', Type => SOCK_STREAM, Reuse => 1); #make sure we are bound to the port die "Cant't create a listening socket:\n$@" unless $listen_socket; warn "Server ready. Waiting for connections ... \n"; if(!-e "$ENV{HOME}/.fifopipe"){system 'mkfifo ~/.fifopipe' || system ' +mknod ~/.fifopipe p' || die $@;} #wait for connections at the accept call while (my $connection = $listen_socket->accept) { my ($pid, $line); # perform the fork or exit if ($pid = fork) { #i'm the parent! #who connected? warn localtime(time)." Connection recieved ... ",$connection-> +peerhost,"\n"; #close the connection, the parent has already passed it off to a c +hild. $connection->close(); open(FIFO, "< $ENV{HOME}/.fifopipe") or die $@; while(<FIFO>){$_ =~ s/a-z/A-Z/i;print $_;} close(FIFO); } else { #i'm the child! #die in case of forking not possible die "Error while forking: $@" unless defined $pid; #close the child's listen socket, we dont need it. $listen_socket->close; open(FIFO, "> $ENV{HOME}/.fifopipe") or die $@; while(<$connection>){print FIFO $_;}; # print FIFO "mouh\n"; close(FIFO); #if the child returns, then just exit; exit; } #go back and listen for the next connection! }

In reply to multiple processes by Mirage

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.