#!/perl

# Client Program
use IO::Socket::INET;

my $host = shift || 'localhost';
my $port = shift || '1234';

print ">> Client Program - host=$host port=$port <<";
# Create a new socket
# $MySocket=new IO::Socket::INET->new(PeerPort=>1234,Proto=>'udp',PeerAddr=>'localhost');
my $MySocket=new IO::Socket::INET->new( PeerPort => $port, # default = 1234,
	Proto => 'udp',
	PeerAddr => $host ); # default = 'localhost'

# Send messages
$def_msg="Enter message to send to server : ";
print "\n",$def_msg;
while($msg=<STDIN>) {
    chomp $msg;
    if($msg ne '') {
        print "\nSending message '",$msg,"'";
        if($MySocket->send($msg)) {
            print ".....<done>","\n";
            print $def_msg;
        } else {
			print "*** SEND FAILED ***\n";
		}
    } else {
        # Send an empty message to server and exit
        $MySocket->send('end');
        $MySocket->send('');
        exit 1;
    }
}


