Cap'n Steve has asked for the wisdom of the Perl Monks concerning the following question:

All I want to do is send a few messages if a certain event happens. Here's the AIM code I have:

use warnings; use strict; use Net::AIM; my $aim = new Net::AIM; $aim->newconn(Screenname => 'TeamMonkeyCrap', Password => '******') or + die $!; my $conn = $aim->getconn(); $aim->start; $conn->send_im('gazuga69', 'It worked!');


All this code does is run until I stop it. I've also tried initializing $conn with $aim->newconn() instead of $aim->getconn() since the documentation and everything on the internet seem to disagree, but it doesn't make a difference. I think the problem is with $aim->start(), but if I remove that it throws an error.

Replies are listed 'Best First'.
Re: I can't seem to figure out Net::AIM
by gargle (Chaplain) on Sep 12, 2005 at 08:04 UTC

    Hi,

    From the documentation:

    $aim->start; his just starts an infinte loop of $aim->do_one_loop;

    do_one_loop executes one read of the socket

    So as I understand it you start looping before ever sending your 'it worked message'.

    Update:node 260416 seems to have a lot more info.

    --
    if ( 1 ) { $postman->ring() for (1..2); }
      Replacing $aim->start; with $aim->do_one_loop; causes the same problem as deleting that line completely. I get this error: "(in cleanup) No method called "handler" for object. at Untitled line 0"

      Adding this line from the node you linked doesn't seem to make a difference, either:
      $conn->set_handler(config => sub {$ready = 1});

        $aim->start; is the same as saying while (1) { $aim->do_one_loop; }. Anything after that whlie loop is never going to get called. Instead of trying to run the do_one_loop by hand you probably want to add a config handler. I beleive that is the best handler and aim calls it after you are logged in. So your code would look something like:

        $conn->set_handler(config => sub { my $aim = shift; $aim->send_im('gazuga69', 'It worked!'); }); $aim->start;


        ___________
        Eric Hodges