Thanks very much for your reply. Clearly and improvement on my $buf = <$EC>. I used both of your code snips but the behaviour did not change. I am still not able to write to the socket, only read from it. The code is entering the for @ok_to_write loop (i changed the array name), where I can print to the server terminal using a bare print "\n"; . But it will not print to the socket.

Trying to write to the client Hello from the client... 1 Trying to write to the client Hello from the client... 2 Trying to write to the client Hello from the client... 3

I tried your code in the isolated client and server (without the fork) and got the same behaviour as before. The data flies between the client and server. I'm pretty sure there's something about the fork that plays a part here. Another difference I notice, is that with forking server, the data from the client is just plodding in.

Here's the code as it now stands in Server_rebuild.pl

#!/usr/bin/perl -w use strict; use IO::Socket; use IO::Select; # Server_rebuild.pl my( $EC, $pid); my $SERVER = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => '50000', Proto => 'tcp', Listen => 3, Reuse => 1, ); die "Could not create socket: $!\n" unless $SERVER; while(1) { # loop for the parent # create a connection to incoming EC accept($EC, $SERVER); next if $pid = fork; # parent die "fork: $!" unless defined $pid; # failure #=================== Now, it's all about the child processes ========= +=========# # the socket of the parent is no use to child close($SERVER); # my $new_sock = $sock->accept(); my( $select, @ok_to_read, @ok_to_write, $buf, $handle2 ); #$handle1, $select = IO::Select->new(); $select->add($EC); while ($EC){ @ok_to_read = $select->can_read(1); @ok_to_write = $select->can_write(1); foreach my $handle1 (@ok_to_read) { my $buf = ''; my $rv = sysread($handle1, $buf, 64*1024, length($buf)); # Handle error # Handle eof while ($buf =~ s/(.*\n)//) { print $1; # Full line at a time } } foreach $handle2 (@ok_to_write){ print $handle2 "Hello from the SERVER new_sock\n"; print $EC "Hello from the SERVER new_sock\n"; print "Trying to write to the client\n"; } #sleep (1); } } #$loop for the parent

In reply to Re^2: Fork is changing up my IO::Select behaviour by Workman
in thread Fork is changing up my IO::Select behaviour by Workman

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.