Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Net::OSCAR: Having trouble getting started

by jpk236 (Monk)
on Jan 28, 2005 at 20:57 UTC ( #426105=perlquestion: print w/replies, xml ) Need Help??

jpk236 has asked for the wisdom of the Perl Monks concerning the following question:

I'm having some trouble with this module. I can't even seem to get it to sign online. Here is the code I'm currently working with:
#!/usr/bin/perl use Net::OSCAR qw(:standard); %signon = ( screenname => 'myscreenname', password => 'mypassword', ); $recipient = "myfriend"; $message = "test message"; $oscar = Net::OSCAR->new(); $oscar->signon(%signon); $oscar->send_im($recipient, $message); $oscar->signoff();
As you can see, I just want something which will sign on, send a message, and sign off. All of these things I want to happen unprovoked (ie: not from first recieving a message from an outside source). Let me know what you guys think.

Thank you Monks.

- Justin

20050130 Edit by castaway: Changed title from 'NET::OSCAR'

Replies are listed 'Best First'.
Re: Net::OSCAR: Having trouble getting started
by jpk236 (Monk) on Jan 29, 2005 at 06:47 UTC
    w00t! Looks like I figured it out. Or rather, looks like I blindly stumbled on code which works. :)
    #!/usr/bin/perl use Net::OSCAR qw(:standard); %signon = ( screenname => 'myscreenname', password => 'mypassword', local_ip => 'myip', ); $recipient = "myfriend"; $message = "mymessage"; sub signon_done { print "signed on\n"; $online = 1; } $oscar = Net::OSCAR->new(); $oscar->set_callback_signon_done(\&signon_done); $oscar->signon(%signon); while(1) { $oscar->do_one_loop(); if ($online) { $oscar->send_im($recipient, $message); sleep(5); } }
    Apparently the $oscar->do_one_loop(); is a pretty important aspect. Thanks for your help!

    - Justin
      Apparently the $oscar->do_one_loop(); is a pretty important aspect. Thanks for your help!

      Yes. That is actualy the meat of how it works. The AIM protocol counts on sending messages back and forth, if its like MSN it uses several connections while doing this. In order for that communication to work and not block your program, it is written in an event based style. This means you setup events to do certain things and then wait for the module to call those events. Inside your connection event the first thing received is actualy the $oscar object. You could then use that to send the message. the way it is currently setup its going to send your message every 5 seconds.


      ___________
      Eric Hodges
      $oscar->loglevel(5);
      or whatever loglevel you put in there, will also give you some useful info.
Re: Net::OSCAR: Having trouble getting started
by edoc (Chaplain) on Jan 29, 2005 at 05:27 UTC

    screename should be screenname? (double n)

    cheers,

    J

      Thanks for catching that typo. Unfortunately, still didn't make things work. :( Let me know what else you think. Thanks.

      - Justin

        ok, then the only other suggestion I would have is to add an error sub to your script. From the docs it looks like that's the only way to see errors..

        something like this should do it:

        sub error{ print join(' - ',@_); }

        pfft! scratch that.. really shouldn't try to think perl when in the middle of a totally unrelated conversation.. The answer's still in there somewhere though I think.

        ahh ok, here we go..

        $oscar->set_callback_error(sub{ print join(' - ',@_) });

        cheers,

        J

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://426105]
Approved by amw1
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2022-05-22 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (80 votes). Check out past polls.

    Notices?