#!/perl
use IO::Socket;

### my $hdr = "$0 $$:";
my $hdr = 'CLIENT5:';
my $msg;
my $host = shift || 'localhost';
###my $port = shift || '7070';
my $port = shift || '5000';

print "$hdr Creating socket host=$host, port=$port ...\n";
my $sock = new IO::Socket::INET (
                                 PeerAddr => $host, ### 'asomatos'
                                 PeerPort => $port, ### '7070'
                                 Proto => 'tcp',
                                );
die "$hdr Could not create socket: $!\n" unless $sock;

sendrcv ('Hello there!');
sendrcv ('How are you?');
sendrcv ('Fine, must run ...');
sendrcv ('end it now');

print "$hdr Closing ...\n";
close($sock);

sub sendrcv {
	local ($m) = @_; # get the message
	print "$hdr Sending ";
	print "[$m]\n";
	print $sock "$m\n";
	print "$hdr Waiting Receive ...\n";
	local $line = <$sock>; # do a READ
	local $len = length($line);
	chomp $line;
	print "$hdr Received [$line]$len ...\n";
}

# EOF
