#!/usr/bin/perl use strict; use warnings; use IO::Socket; my $incoming; my $check; my @check; my @command; my $new_sock; my $sock = new IO::Socket::INET ( LocalPort => '8888', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; $new_sock = $sock->accept(); while ($incoming = <$new_sock>){ print "hi"; if ($incoming =~ m/.+/){ print $incoming; @command = split / /,$incoming; $command[1] =~ s/\W+//g; $incoming = ""; if ($command[0] eq "check"){ $check = @check = `ps -ef |grep $command[1]`; print "$check\n@check\n"; if ($check >= 12) { print $new_sock "up"; } else { print $new_sock "down"; } }else{ print"did not work\n"; } } } close $sock;
#!/usr/bin/perl use strict; use warnings; use IO::Socket; use Fcntl; my $input; my $sock; my $cs2; my $mqpcx; my $mpts; my $EOL = "\015\012"; my $BLANK = $EOL x 2; my $command; open OUT, "> testpage.html" or die "unable to write testpage"; ### OUT is temporary until I get cgi working. open FILE1, "< 1.html" or die; while (<FILE1>){print OUT} close FILE1; $sock = new IO::Socket::INET ( PeerAddr => '53.230.116.97', PeerPort => '8888', Proto => 'tcp', ); if ($sock){ print "Connection established\n"; $command = "check cs2" . $BLANK; print $sock $command; while ($cs2 = <$sock>){ last if ($cs2 =~ m/.+/); } if ($cs2 eq "up") { print OUT "<img src=\"./cs2up.gif\">\n"; $mpts++; print"so far, so good\n"; } elsif ($cs2 eq "down") { print OUT "<img src=\"./cs2down.gif\">\n"; } else { print "error getting data from other box"; } }else{ print OUT "<img src=\"./cs2down.gif\">\n"; print "no connection to other box"; } close($sock); close OUT; print "goodbye\n";
Believe nothing, no matter where you read it, or who said it - even if I have said it - unless it agrees with your own reason and your own common sense.
(Buddha)
In reply to Re^3: two-way socket works once only?
by wolfger
in thread two-way socket works once only?
by wolfger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |