#! /usr/bin/perl

use IO::Socket;

$alarm_timeout = 15;

$data = $ARGV[0];

$passwd = "public";

#
# Setup a subroutine for when the alarm
# fires
#
$SIG{'ALRM'} = 'alarm_fired';

$sock = new IO::Socket::INET (PeerHost => 'cosmov03',
                              PeerPort => '5500',
                              Proto    => 'tcp',
                              Timeout  => '5',
                             );

die "Socket could not be created: $!\n" unless $sock;

print "Sending login/password: $passwd\n";

print $sock "login:$passwd\n";


print "Waiting for response\n";

if ($buf = <$sock>) {
  print "answer was: $buf\n";
}

print $sock "get_info:$data\n";

if ($buf = <$sock>) {
  print "answer was: $buf\n";
}

print "Logging out\n";

print $sock "logout\n";

close ($sock);

exit;

sub alarm_fired {

  my ($result) = "";

  &log("Timed out waiting on socket connection ($alarm_timeout sec.)");
  &log("Returning 0");
  exit 1;


}
