Hello, I have a forked process here with one child, each process runs its own while loop. The parents job is to read STDIN then send it to the server; while the job of the child is to print any recieved messages from the server even while the parent is waiting for stdin. I assumed this would work but it seems as soon as the child attempts to recv() from the server to check for messages - the parent stops and the tcp connection appears broken. Im sure I do not fully understand the inner workings of how perl deals with the tcp connection so I might be making my mistake there, thank you

use v5.14; use Socket; $| = 1; my $user_name = 'default'; socket(SERVER,PF_INET,SOCK_STREAM,getprotobyname('tcp')); my $iaddr = inet_aton('localhost'); my $packed_addr = sockaddr_in(5555, $iaddr); connect(SERVER,$packed_addr) or die "Cant connect: $!\n"; print STDERR "[Connected to server as \"$user_name\"]; \tfor a list + of commands type /help\n"; send(SERVER,$user_name,1); if(my $pid = fork){ while (1){ print "Send: "; chomp(my $data = <STDIN>); send(SERVER,$data,1); } } else{ while(1){ if( recv(SERVER,my $info,1024,0) ){ say $info; } } }

In reply to recv() on forked process by Rudolf

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.