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;
In reply to IO::Socket hangs reading data from server by halfbaked
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |