#!/usr/bin/perl # c.pl use strict; use warnings; use IO::Socket; use less 'java'; #;-) my $b_address = '127.0.0.1'; #IP of box A my $b_port = '8888'; #Port number guipartner set to on A my $eol = "\015\012"; #sets end of line chracters for socket transmissions my $skipC = 0; my $socketC; eval { # set the signal handler. we die when the signal hits us local $SIG{ALRM} = sub { die("timeout\n") }; alarm(5); # number of seconds for timeout $socketC = new IO::Socket::INET ( PeerAddr => $b_address, PeerPort => $b_port, Proto => 'tcp', ); alarm(0); # cancel the alarm signal }; # we got the alarm signal, so we timed out if ($@ eq "timeout\n") { print "socket not available\n"; exit; } # some other unexpected error elsif ($@) { die($@); } local $/=$eol; #set default EOL to $eol so chomp works while (!$skipC) { print $socketC "c.pl sends \$skipC=$skipC", $eol; print "message sent\n"; sleep 2; } print "socket not available\n"; close $socketC;