#!/usr/bin/perl -w use IO::Socket; # create a tcp connection to the specified host and port $client = IO::Socket::INET->new( Proto => "tcp", PeerAddr => 'localhost', PeerPort => '6969' ), or die "can't connect to server: $!"; print $client "READY\n"; while (<$client>) { if (/GO/i) { srand; # seed the random number function $num = int (rand 3); # get a random integer, 0 through 2 if ($num == 0) { print $client "Rock\n"; } elsif ($num == 1) { print $client "Paper\n"; } elsif ($num == 2) { print $client "Scissors\n"; } } if (/STOP/i) { last; } } close $client;