Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-12-08 19:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?