#!c:/perl/bin/perl -w $|++; use strict; use IO::Socket::INET; # Number of times to attempt a server connection my $max_attempts = $ARGV[0] || 10000; my $sock; for my $i (1 .. $max_attempts) { $sock = IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => '7070', Proto => 'tcp' ); if (defined $sock) { print "Connection to server established.\n\n"; last; } else { print "Attempt $i/$max_attempts failed.\n"; die "Could not connect to the server.\n\n" if $i == $max_attempts; } sleep 2; } # Continually grab input from the server my $byte; print $byte while sysread($sock, $byte, 1); close $sock;