#!/usr/bin/perl
use IO::Socket; #use the socket interface.
print "=====================\n"; #by Cypher
print "Enter hostname to connect: "; chomp($host=<STDIN>); # get hostname info

$hostname='localhost';
$hostname = $host if $host; #if no host entered, connect to localhost

print "Connecting to $hostname...\n";

my $so = new IO::Socket::INET(PeerAddr => $hostname,
				PeerPort => '5446',
                                 Proto => 'tcp',); #define a new socket for use
die "Socket Error: $!\n" unless $so; #check whether socket is working

print "Send: "; 
while($msg=<STDIN>) { 
	print $so "$msg\n"; #send message to server
	last if ($msg eq "exit"); #check for exit command
	print "Send: ";
}
close ($so); #close connection