in reply to Re: Net::AIM with another script?
in thread Net::AIM with another script?

One other question. How will I actually get the data to the AIMbot? I somehow need the connection pointer (which is now running in a different script?). Once I do a $aim->start; I'm in an infinite loop ($aim->do_one_loop), and I can't execute any other code UNLESS I get an event off the toc server.... how can POE help me do this? Thanks again.

Replies are listed 'Best First'.
Re: Re: Re: Net::AIM with another script?
by eric256 (Parson) on Aug 17, 2003 at 06:22 UTC

    Instead of running start, run do_one_loop, in a continous set of poe events.

    I would just include any HTML generation as part of the same script, if you want it to happen at set intervals then use POE to do it.

    For learning poe i would just set it up on a computer, and have it print something every 5 seconds, and then figure out how to get it to print one thing every 5 seconds and another every 7, then you basicaly have the base for what you need. Fix the intervals and have one generate HTML and the other call do_one_loop. Its realy easier than it sounds once you get poe running.

    ___________
    Eric Hodges
      Any chance you can point me to URL for a good example script? I'm not really sure where to start... there seem to be a lot of uses and applications of POE from looking at poe.perl.com

        I haven't read it (I plan to), but there was recently An introduction to POE posted to the monastery. You may want to start there.

        kelan


        Perl6 Grammar Student

        The POE site does seem a little complex. Here is an example of a script that calls one function once, then that function starts a loop of calls to a second function.

        use strict; use POE; use POE::Session; POE::Session->create( inline_states => { _start => \&start, #_start + is automagicaly the first event continue => \&looping #user defin +ed event we will call later } ); $poe_kernel->run(); sub start { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Starting in 5!\n"; $kernel->delay( continue => 5 ); # call the continue event in fi +ve seconds } sub looping { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; $heap->{counter}++; #the heap is just a hash we can put goodi +es in. print "$heap->{counter} iteration!\n"; if ($heap->{counter} < 10) { $kernel->delay( continue => 1 ); #start state continue in 1 +seconds } }

        Now that might look confusing but try it out. Its actualy very nice, and fun. Beats the crap out of making a loop and having counter variables to see if its time to run it or not.

        Now here is the same code, but i cut and pasted parts and changed the intervals. This is why poe is pretty!

        use strict; use POE; use POE::Session; POE::Session->create( inline_states => { _start => \&start, #_start + is automagicaly the first event continue => \&looping #user defin +ed event we will call later } ); POE::Session->create( inline_states => { _start => \&start2, #_star +t is automagicaly the first event continue => \&looping2 #user defi +ned event we will call later } ); $poe_kernel->run(); sub start { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Starting A in 5! (Loops every .5 seconds) \n"; $kernel->delay( continue => 5 ); # call the continue event in fi +ve seconds } sub looping { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; $heap->{counter}++; #the heap is just a hash we can put goodi +es in. print "A: $heap->{counter} iteration! \n"; if ($heap->{counter} < 100) { $kernel->delay( continue => .5 ); #start state continue in 1 + seconds } } sub start2 { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Starting B in 7 (Loops every 2 seconds)!\n"; $kernel->delay( continue => 7 ); # call the continue event in fi +ve seconds } sub looping2 { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; $heap->{counter}++; #the heap is just a hash we can put goodi +es in. print "B: Iteration number $heap->{counter}!\n"; if ($heap->{counter} < 100) { $kernel->delay( continue => 2 ); #start state continue in 1 +seconds } }

        Tested and pre-approved. :-)

        ___________
        Eric Hodges