|more useful options|
Building a simple service scanner with POEby grinder (Bishop)
|on Sep 09, 2005 at 15:39 UTC||Need Help??|
grinder has asked for the
wisdom of the Perl Monks concerning the following question:
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:
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