Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I've been trying to wrap my head around POE. I have a lengthy script that sees whether it can open a socket on various ports on various machines (over 100 connecctions all told). Actually the script is short, it just takes a long time to run, since everything is done serially.

It's just too slow... so I finally found some time to investigate POE, and I have the following code:

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->{por +t} down\n" }, ConnectTimeout => 2, ServerInput => sub { }, ); } $poe_kernel->run();

This actually works quite well. It takes less than a second to run if all services are up, and a smidgen more than two seconds if a service is down. Much better than the 13 seconds the old script takes.

It does, however, have a major flaw, in that it doesn't know how to deal with UDP. I use the POE::Component::Client::TCP module to deal with TCP protocols, but there's no such thing as POE::Component::Client::UDP, and I don't know how to go about using the POE building blocks to make something that would work. All I need is a true/false result to the question "could I open a socket".

The other flaw that I don't like is the klugey empty ServerInput callback. It's never called, but the object cannot be constructed if this key/value pair is missing. This may mean that I'm using POE::Component::Client::TCP for a purpose for which it was not designed. Which in turn may mean that I'm paying for a lot of startup overhead that may be avoided by using some other technique. Again, just like for UDP, I'm only interested in a yes/no answer.

I also suspect that both of these flaws are probably solved by one simple(r)? solution. Can someone set me straight?

- another intruder with the mooring in the heart of the Perl


In reply to Building a simple service scanner with POE by grinder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (4)
    As of 2014-10-26 03:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (150 votes), past polls