Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl; #use strict; use warnings; use IO::Socket::INET; my $server='192.168.178.6'; my $port='50099'; my $user='monitor'; my $pass='monitor'; $sock = IO::Socket::INET->new(PeerAddr => $server, PeerPort => $port, Proto => 'udp') or die("ERROR open Socket $server:$port ( +$@)\n"); $sock->autoflush(1); my($in, $buf, $kid, $count); die "fork fail: $!" unless defined($kid = fork); if ($kid) { print $sock "login monitor monitor"; select(undef, undef, undef, 0.5); #sleep 0.5s print $sock "log on"; select(undef, undef, undef, 0.5); print $sock "status"; while(1) { print $sock "log on"; sleep(10); }; # kill the child process #kill(TERM => $kid); } else { while(1) { $buf = <$sock>; print $buf; if ($buf =~ m/.*Nat.*/) { $count++; print "Count $count"; }; }; close $sock; }
The "$kid" logs on to an UDP server application and in the while loop makes sure that the connection does not time out. The "else" part constantly monitors the server output and has some rules (here simplified example) that react to the output.
Now I want to send further commands, similar to the "log on" in the while loop. They shall be based on timers and/or reactions to the parsed output of the server.
Any help to my meagre Perl skills would be really appreciated.
|
|---|