in reply to Re^2: Recieving reply from a socket
in thread Recieving reply from a socket

because readline blocks

Replies are listed 'Best First'.
Re^4: Recieving reply from a socket
by Anonymous Monk on Mar 19, 2009 at 15:41 UTC
    Does this mean the server is not repling? Hers my code -
    use strict; use warnings; use IO::Socket::INET; my $socket = IO::Socket::INET->new(PeerAddr => "localhost", PeerPort => 12323, Proto => 'tcp'); print $socket "Hi!"; my $response = <$socket>; print $response; $socket->close();

      Anonymous Monk has said that readline (i.e. my $response = <$socket>) blocks. This basically means that if the server is not ending its message with a newline, then readline will sit waiting for it. You can get around this by either 1) editing the server code so that it sends newlines or 2) using recv, which will allow you to specify how much you want to read.

      What server are you connecting to? If you have the code, posting the relevant parts would be a great help.

      Also, I hate to sound like a broken record, but Suffering from Buffering is a very good read.

      Using telnet I do: telnet localhost 12323, and then enter Hi! and press return and I get a response. BTW, I have tried this also: print $socket "Hi!\n"; What's my problem? Thanks.