dynamopsychism has asked for the wisdom of the Perl Monks concerning the following question:

This is confounding me. Everything is apparently written correctly and yet it's not reading properly from the socket I've created. It's writing correctly, as well.
use strict; use IO::Socket::INET; my $remote_host = "127.0.0.1"; my $remote_port = 950; my $socket; $socket = IO::Socket::INET->new(PeerAddr => $remote_host, PeerPort => +$remote_port, Type => SOCK_STREAM, Proto => "tcp") || die "Problem: $ +!\n"; print $socket "sp100\r"; my $data = <$socket>; print STDOUT $data; close $socket;
Any ideas?

Replies are listed 'Best First'.
Re: Why won't this read?
by Anonymous Monk on May 23, 2001 at 01:54 UTC
    Are you sure the server is sending the correct data to the client? What happens when you run:
    use strict; use IO::Socket::INET; my $remote_host = "www.perlmonks.org"; my $remote_port = 80; my $socket; $socket = IO::Socket::INET->new(PeerAddr => $remote_host, PeerPort => +$remote_port, Type => SOCK_STREAM, Proto => "tcp") || die "Problem: $ +! +\n"; print $socket "GET / HTTP/1.0\r\n\r\n"; my $data = <$socket>; print STDOUT $data; close $socket;
    If that prints out "HTTP/1.1 200 OK" then there is probably a problem with the server and not the client.
      Ooops, a pair of +'s in there were copied from the red line wraps in the original message. Fortunately they don't affect the code.
      The server responds independently of the client. I can make the server spit stuff out at will, and I'm snooping it over a serial device at the wire level, so I know the server is doing its business. It's still not reading. Any ideas?
Re: Why won't this read?
by traveler (Parson) on May 23, 2001 at 02:11 UTC
    Or you can try the orig. code with $remote_port=7; which is the echo port. I know it tests reading and writing, but then you know the code is right if it works.
    Be sure you or some sysadmin has not turned off echo/tcp. To test this do a telnet to port 7 and see if your input is echoed. You can also use a telnet to your server to see if it echoes.
Re: Why won't this read?
by Anonymous Monk on May 23, 2001 at 13:38 UTC
    \r is not the End Of Line. The Server gets your command after it has received EOF because EOL is missing. *Then* it does it's answer. But EOF is sent when the Client terminates which has the unfortunate effect that a terminated Client can't read anything.