http://www.perlmonks.org?node_id=489032


in reply to Re: Using select() on only one socket
in thread Using select() on only one socket

Yes, a lot of lines come in.
  • Comment on Re^2: Using select() on only one socket

Replies are listed 'Best First'.
Re^3: Using select() on only one socket
by GrandFather (Saint) on Sep 04, 2005 at 10:07 UTC

    The Camel has the following to say (much better than I could!):

    A common misconception in socket programming is that \n will be \012 everywhere. In many common Internet protocols, \012 and \015 are specified, and the values of Perl's \n and \r are not reliable since they vary from system to system:

    print SOCKET "Hi there, client!\015\012"; # right print SOCKET "Hi there, client!\r\n"; # wrong

    However, using \015\012 (or \cM\cJ, or \x0D\x0A, or even v13.10) can be tedious and unsightly, as well as confusing to those maintaining the code. The Socket module supplies some Right Things for those who want them:

    use Socket qw(:DEFAULT :crlf); print SOCKET "Hi there, client!$CRLF" # right

    When reading from a socket, remember that the default input record separator $/ is \n, which means you have to do some extra work if you're not sure what you'll be seeing across the socket. Robust socket code should recognize either \012 or \015\012 as end of line:

    use Socket qw(:DEFAULT :crlf); local ($/) = LF; # not needed if $/ is already \012 while (<SOCKET>) { s/$CR?$LF/\n/; # replace LF or CRLF with logical newline }


    Perl is Huffman encoded by design.
      I'm using IO::Socket, not Socket... and in my case \n is \n ;)If I just do
      while (<$sock>){ print; }
      I see everything printed normaly with line separated by '\n'.
      If I send lines terminated by '\n', the server responds normaly. I don't think the problem is right here.