Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Using select() on only one socket

by dws (Chancellor)
on Sep 04, 2005 at 09:20 UTC ( #489031=note: print w/replies, xml ) Need Help??

in reply to Using select() on only one socket

.. nothing happens. Any ideas?

Unless you've done something interesting with $/ , $line = <$socket>; tries to read a complete line of text from the socket, blocking until one is available. Is there a full line available?

Replies are listed 'Best First'.
Re^2: Using select() on only one socket
by ivanatora (Sexton) on Sep 04, 2005 at 09:27 UTC
    Yes, a lot of lines come in.

      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?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2020-10-26 18:56 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (252 votes). Check out past polls.