I wrote a whois program in perl. Here is the connection part of the program:
use IO:

ocket;
$remote="whois.crsnic.net";
$sock=IO:

ocket::INET->new(Proto=>'tcp',PeerAddr=>"$remote:43");
$sock->print("domain $dm.$tld\n") ;
my @result=$sock->getlines;
close($sock);
When running the program it freezes at random points. Sometimes after scanning 10 domains other times after a couple hundred. I'm getting the following errors:
1. Connection reset by peer
This occurs on
my @result=$sock->getlines;
It happens quite often and sometimes freezes completely after printing this error.
2. Bad file descriptor
This error occurs on
$sock=IO:

ocket::INET->new(Proto=>'tcp',PeerAddr=>"$remote:43");
It happens sometimes and often freezes completely after printing this error.
3. Operation now in progress
This error occurs on
$sock=IO:

ocket::INET->new(Proto=>'tcp',PeerAddr=>"$remote:43");
It happens less often than the other errors and doesn't appear to freeze the program.
4. Unknown error
This error occurs on
$sock=IO:

ocket::INET->new(Proto=>'tcp',PeerAddr=>"$remote:43");
It's only happened 3 times and I'm not sure why. It doesn't seem to freeze the program.
Those are the 4 errors I have seen when testing the program. It is completely random. Sometimes it works just fine and other times prints one of those errors and freezes. Sometimes it just freezes without printing anything. I have tried setting a timeout and tried several different variations of the code with different modules for making the connection to the whois server. I have tried the code on Windows and Linux at different locations, but I still get one of those errors and it usually freezes afterward. I have placed print statements throughout to make sure I wasn't stuck in an infinite loop somewhere. I have run out of ideas. Can anyone help?