I'm writing an AIM bot using Net::OSCAR. When net connection is lost it goes offline. I need to find a way to periodically check if its online or not. But, I don't find a method in Net::OSCAR to check this. Anyone have any idea how to check if the connected bot is online or not?

Edit: I may be confused. Do you want the bot to check for a connection so it can sign back in when it comes back up OR do you want a different script that will check AIM to see if your bot is listed as on line? ---------- The vastness of what we know is only surpassed by the vastness of what we don't.

What you're planning sounds good to me. I am unfamiliar with that module though, so someone who knows it might have a better solution. ---------- The vastness of what we know is only surpassed by the vastness of what we don't.

It may actually be easier just to try to send yourself an IM, though, lol.

-- EDIT :: This, of course, only works for checking that you are actually signed on when you initiate the sign on. The module does provide good return information when you make a call, so I highly suggest capturing and checking that info for detecting random disconnects.

I noticed that by default Net::OSCAR will not not stealth when you sign in, you have to pass it extra flags if you want to do that. If you are worried about your bot being signed on in invisible mode, I don't think you need to be. ---------- The vastness of what we know is only surpassed by the vastness of what we don't.

this one only checks if the bot got logged in... the problem is that sometimes the bot gets logged out... this is where my problems begins... there is no function or callback to check if the bot is online or not...

To do it right, you will have to set up a callback for $oscar->set_callback_error();

This gets called when any error is encountered. Your callback sub will have to look through the info returned and figure out if you've disconnected. ---------- The vastness of what we know is only surpassed by the vastness of what we don't.

You need to provide more information and at least some of your code if you wish for other people to help you troubleshoot.

Only stating it didn't work discourages people from assisting you, since it gives the impression you have put little to no work into it and want other people to do all the work for you.

So, are you receiving an error when you try to run your script? If so, what does it say? Please also post a copy of your error handling subroutine. I'll do what I can to assist you. ---------- The vastness of what we know is only surpassed by the vastness of what we don't.

This is my error handler. But, this one doesn't get called when connection drops.

The issue can be recreated by creating a sample program and switching off your LAN interface ( may ifdown eth0 or pull out the cable ) while running it. The bot goes offline after some time but error callback function won't get called.

Yeah, after re-reading the module info it seems to me that that error sub only gets called on certain error events. Disconnecting or loosing connection is not one of them.

I assume your bot is sending and receiving IMs when it will disconnect, and it looks like there is no callback to the error sub when sending an IM fails.

So, it looks like detecting failures to send IMs is the best way to know if you have been disconnected. Fortunately there are several things you can do.

I think, based on what the module says, that the best way to do it is to catch the request IDs generated by send_im() and use the im_ok() callback to verify that your messages are being sent.

Example for callback:

Code

### Create hash to hold im request ids %im_request_ids = ();

sub im_sent_ok { my($oscar, $to, $request_id) = @_;

if($im_request_ids{$request_id}) { ### Message was sent by me, and the time is logged there.

### Blank out the time, so the ID doesn't get checked $im_request_ids{$request_id} = 0;

### Attempt to undefine it. Not sure if this is appropriate or will work (double check) ### If it does work, it will keep the size of the hash down undef $im_request_ids{$request_id}; } else { ### Doesn't look like I sent a message with that request id, error }

}

$oscar->set_callback_im_ok(\&im_sent_ok);

When you send an IM, here's how my example would catch the request id: