in reply to IO::Socket hangs reading data from server

Just add Blocking => 0.
!/usr/bin/perl use strict; use warnings; use Data::Dumper; use IO::Socket; my $socket = IO::Socket::INET->new( PeerAddr => 'all.dict.org', PeerPort => '2628', Proto => 'tcp', Timeout => 1, ReuseAddr => 1, MultiHomed => 1, Blocking => 0); die ("Could not create socket: $!\n") unless $socket; $socket->send("CLIENT dict4perl\n"); my $buf; while (sysread($socket, $buf, 1024)) { print $buf; } print "Done\n"; 1;

Replies are listed 'Best First'.
Re^2: IO::Socket hangs reading data from server
by halfbaked (Sexton) on Sep 09, 2010 at 00:24 UTC

    Thanks for information, with Blocking => 0 the application doesn't hang but it also doesn't seem to allow me to pull any of the response data from the server.

    Probably another problem, but I've also tried to pull the response data with:

    $socket->send("CLIENT dict4perl\n"); my $buf; while ($socket->recv($buf, 1024)) { print $buf . "\n"; }

    But no luck. I'm missing something here.

      Scratch that it works fine, there's something wiggie with my Mac shell and printing data with a shell script. It works in mod_perl where I want it to work.

      Thanks again for your help.

      This is without a doubt the most useful Web site on the Internet. It's one of the reasons I stick with Perl, other than that it's a kick ass language.