client2.pl to HTML.

index -|- end

Generated: Tue Feb 2 17:54:26 2010 from client2.pl 2005/05/05 952.

#!/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;
    }
}

index -|- top

checked by tidy  Valid HTML 4.01 Transitional