#! /usr/bin/perl
use strict;
use Socket;

my $server_port = 5432 ;
my $max_line = 256 ;

if ( $#ARGV == 0 )
{
    $host = $ARGV[0] ;
}
else
{
    print STDERR "usage: simplex-talk host\n" ;
    exit 1 ;
}

if (! ($hp = gethostbyname($host)))
{
    printf STDERR "simplex-talk: unknown host: ${host}\n" ;
    exit 1 ;
}

$sin = sockaddr_in($server_port, $hp) ;

if (!socket(SOCK, PF_INET, SOCK_STREAM, 0))
{
    print STDERR "simplex-talk: socket" ;
    exit(1) ;
}

if (!connect(SOCK, $sin))
{
    print STDERR "simplex-talk: connect" ;
    close(SOCK);
    exit(1) ;
}

select((select(SOCK), $| = 1)[0]) ;

while (my $line = <STDIN>)
{
    print SOCK $line ;
}
