in reply to socket gone crazy

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...)

Replies are listed 'Best First'.
Re^2: socket gone crazy
by jettero (Monsignor) on May 23, 2007 at 15:46 UTC

    I'm also under the impression that changing $/ might not ever help with this since the \n is converted on the way in from a file handle. The thing I don't know is if it converts "\x0d\x0a" to a \n for sockets. I suspect it does not.

    -Paul

      ... changing $/ might not ever help with this since the \n is converted on the way in from a file handle.

      Automatic line ending translations would happen if the crlf PerlIO layer were in effect. On Windows, this layer is by default pushed on the PerlIO layer stack for every filehandle (and, I suppose, for sockets, too — not 100% sure, though1).  However, as the OP is trying this on Ubuntu, there is no crlf layer (unless explicitly requested), and thus no CR/LF translations.

      ___

      1 ...sorry, can't verify without rebooting into Windows, which would be too much fuss at the moment :)

      Maybe someone else is willing to just run the example on Windows, and put a

      print join(" ", PerlIO::get_layers($session)), "\n";

      right after the my $session = $sock->accept; in the server code. This would show which layers are in effect.