Hi, The problem with doing it in client_start is I can only do a few at a time, so by shifting the array in got_pong means I will never go beyond my "limit" of 20 at a time. Any ideas on how to accomplish this? Thanks...
"Dan McCormick" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > You just need to call exit() at some point. This will stop your script > and close your file. > > How and when to do that is another matter -- you may want to push the > addresses you ping onto an array, and then pop them off in > client_got_pong(). When the array is empty, exit. Or do the same thing > with a hash -- add a key when pinging, delete it when you get the > response. > > I think you may need to tweak the current logic you use with > @addresses. It looks like you shift the entire array in client_start() > but then try again in client_got_pong() -- by that time, however, > @addresses is empty. > > You can also, ya know, just do this in client_start: > > foreach my $address (@addresses) { > ... > } > > and avoid the shift'ing and 'last unless defined' check altogether. > > Dan > > On Thu, 2003-08-28 at 15:28, [EMAIL PROTECTED] wrote: > > I'm having a problem with the script below. It runs through all my addresses > > fine but when it gets to the last one in the array, the program just hangs > > there. My output file is empty so it hasn't been closed yet but if I hit > > CTRL-C, the file is closed and the script stops. I assume I need to somehow > > say my array of addresses is done but how would I do that below? Any help > > would be greatly appreciated. > > > > #!/usr/bin/perl -w > > > > BEGIN { > > die "POE::Component::Client::Ping requires root privilege\n" > > if $> and ( $^O ne 'VMS' ); > > } > > > > use POE; > > use POE::Component::Client::Ping; > > > > # How many seconds to wait for ping responses. > > sub PING_TIMEOUT () { 5 } > > > > my $outfile = "/logs/tpaping3.log"; > > > > my @addresses = qw(1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4); > > > > POE::Component::Client::Ping->spawn > > ( Alias => 'pinger', > > Timeout => PING_TIMEOUT, > > OneReply => 1 > > ); > > > > POE::Session->create > > ( inline_states => > > { _start => \&client_start, > > pong => \&client_got_pong, > > } > > ); > > > > open (OUT_FH, "> $outfile"); > > print OUT_FH "Started ".scalar(localtime)."\n"; > > $poe_kernel->run(); > > close (OUT_FH); > > exit; > > > > sub client_start { > > my ( $kernel, $session ) = @_[ KERNEL, SESSION ]; > > print "Starting to ping hosts.\n"; > > for (1..20) { > > my $address = shift @addresses; > > last unless defined $address; > > print "Pinging $address at ", scalar(localtime), "\n"; > > $kernel->post( pinger => ping => pong => $address ); > > } > > } > > > > sub client_got_pong { > > my ( $kernel, $session ) = @_[ KERNEL, SESSION ]; > > my $request_packet = $_[ARG0]; > > my ( $request_address, $request_timeout, $request_time ) = > > @{$request_packet}; > > my $response_packet = $_[ARG1]; > > my ( $response_address, $roundtrip_time, $reply_time ) = > > @{$response_packet}; > > if (! defined $response_address ) { > > print OUT_FH "Timed out waiting for responses from $request_address.\n"; > > } > > my $address = shift @addresses; > > if (defined $address) { > > print "Pinging $address at ".scalar(localtime)."\n"; > > $kernel->post( pinger => ping => pong => $address ); > > } > > } > > > > >
