#!/usr/bin/perl
#
#
use IO::Socket::INET;

my $hostname = shift;
my $port     = shift;

if (!$port) {
    print "usage: $0 <hostname> <port>\n";
    exit 1;
}

$| = 1;     # auto-flush

my $socket = new IO::Socket::INET (
    PeerHost => $hostname,
    PeerPort => $port,
    Proto => 'tcp',
) or die "Cannot connect to $hostname:$port: $!\n";

while (my $input = <>) {
    if (!$socket->send($input)) {
        die "Cannot send data to $hostname:$port: $!\n";
    }
}
shutdown($socket, 1);
my $response = '';
$socket->recv($response, 1024);
print $response;

$socket->close();

