halfbaked has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to write a simple DICT client, but I've been tripped up by my lack of sockets knowledge.
The problem is that when I'm reading the response from the server the client hangs when there's no more data rather than moving on like I want it to.
I'd like to issue a command, read the server response, and then issue another command. If I know how much data is being returned from the server for a specific command, I can call sysread the correct number of times and it works, but that just seems silly to call it twice sometimes, thrice another and once other times.
#!/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 => 10, Resue => 1, MultiHomed => 1); 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: IO::Socket hangs reading data from server
by Khen1950fx (Canon) on Sep 08, 2010 at 23:09 UTC | |
by halfbaked (Sexton) on Sep 09, 2010 at 00:24 UTC | |
by halfbaked (Sexton) on Sep 09, 2010 at 00:28 UTC |