Hello,
I realize that there's been a few very similar threads on hanging sockets but none of the fixes that worked for others seem to work for this issue, so I thought I'd add it to the heap.
I've got a POE TCP server running on localhost on a Windows box with ActivePerl 5.8.8. A pure-POE client-server setup works fine. Both sides can read/write. However on the client side I just want a simple connect->write->read->disconnect. No need for the extra event handling. So I tried using IO::Socket::INET to do it.
The problem is, no matter what I do the script hangs while trying to read from the socket. I've tried reading with
<$socket> in a loop. I've tried it outside of a loop. I've tried
sysread($socket, $buf, 1024) in and out of a loop. I've tried doing
shutdown($socket, 1). I've tried setting
$/ to some other string and passing it through the server and it still hangs. Right now the code looks like this:
use IO::Socket::INET;
$socket = IO::Socket::INET->new(
PeerAddr => '127.0.0.1',
PeerPort => 5555,
Proto => 'tcp',
Type => SOCK_STREAM,
Timeout => 5,
) or die $@;
$socket->autoflush(1);
print $socket "Hello!\n";
my $line = "";
sysread($socket, $line, 1024);
print "ANSWER: " . $line;
close($socket);
The server receives the "Hello!" and responds, but the client hangs on the
sysread without ever receiving any data.
Thanks for taking the time to read this.