use strict; use POE; use POE::Component::Client::TCP; my $task = [ { name => 'www.example.com', proto => 'tcp', port => 80 }, { name => 'smtp.example.com', proto => 'tcp', port => 25 }, { name => 'ns.example.com', proto => 'udp', port => 53 }, ]; for my $t( @$task ) { next if $t->{proto} ne 'tcp'; POE::Component::Client::TCP->new( RemoteAddress => $t->{host}, RemotePort => $t->{port}, Connected => sub { print "$t->{host}:$t->{proto}:$t->{port} up\n"; $poe_kernel->yield( 'shutdown' ); }, ConnectError => sub { print "$t->{host}:$t->{proto}:$t->{port} down\n" }, ConnectTimeout => 2, ServerInput => sub { }, ); } $poe_kernel->run();