
# Vital libraries
use Socket;
#use SelfLoader;


sub error
{
   print "$_\n";
}

# check_socket(host, port, handle, [&error])
sub check_socket
{
local($addr, $h); $h = $_[2];
if (!socket($h, PF_INET, SOCK_STREAM, getprotobyname("tcp"))) {
	if ($_[3]) { ${$_[3]} = "Failed to create socket : $!"; return false; }
	else { &error("Failed to create socket : $!"); }
	}
if (!($addr = inet_aton($_[0]))) {
	if ($_[3]) { ${$_[3]} = "Failed to lookup IP address for $_[0]"; return false; }
	else { &error("Failed to lookup IP address for $_[0]"); }
	}
if (!connect($h, sockaddr_in($_[1], $addr))) {
	if ($_[3]) { ${$_[3]} = "Failed to connect to $_[0]:$_[1] : $!"; return false; }
	else { &error("Failed to connect to $_[0]:$_[1] : $!"); }
	}
        # select($h); $| =1; select(STDOUT);
        shutdown($h,2);
        return true;
}

 
 $rv = { 'fh' => time().$$ };  

 $port="5427";
 $host="alhambra";
 $errormsg="";
 $stat_sck=&check_socket($host, $port, $rv->{'fh'},\$errormsg );
   print "$errormsg\n" ; 
 if ( $stat_sck eq true ) {

   print "HOLA\n" ; 
}
