Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Using select() on only one socket

by ivanatora (Sexton)
on Sep 04, 2005 at 09:27 UTC ( [id://489032]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://489032]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found