jettero identified the problem correctly. However, setting $/ = CRLF on the client side won't help, as it's the input record separator, yet the \r\n (CRLF) needs to be sent on output, i.e. at the end of the $msg_out string in the statement print $socket $msg_out; .

Anyway, the easiest way to get this demo to work is to remove the $/ = CRLF; in the server code. Alternatively, you could add $msg_out =~ s/\n/\r\n/; right before the print $socket $msg_out; . (On unix, the string returned by STDIN->getline will be terminated by just \n, not \r\n.)

With this modification, you should see (assuming the server is running):

$ ./tcp_echo_cli2.pl localhost 2007 foobar raboof

BTW, a good way to debug things like these yourself is to insert simple print ... statements to find out exactly where things are not working as expected. (In this case, you'd have seen that it doesn't get past the while (<$session>) { line in the server...)


In reply to Re: socket gone crazy by almut
in thread socket gone crazy by spx2

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.