Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2022-01-26 14:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (69 votes). Check out past polls.

    Notices?