Created
September 8, 2012 20:00
-
-
Save sugar84/3679238 to your computer and use it in GitHub Desktop.
AnyEvent::XMPP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use common::sense; | |
use AnyEvent; | |
use AnyEvent::XMPP::Client; | |
my $cv = AE::cv; | |
my $client = AnyEvent::XMPP::Client->new(debug => 1); | |
$client->add_account('[email protected]', 'password'); | |
my $timer; | |
$client->reg_cb( | |
session_ready => sub { | |
my ($client, $acc) = @_; | |
$client->send_message( | |
"Hello! Jabber message!", '[email protected]', | |
undef, 'chat' | |
); | |
$timer = AE::timer 2, 0, sub { | |
$client->disconnect; | |
}; | |
}, | |
disconnect => sub { | |
my ($client, $acc, $h, $p, $reas) = @_; | |
say "disconnect ($h:$p): $reas"; | |
$cv->send; | |
}, | |
error => sub { | |
my ($client, $acc, $err) = @_; | |
say "ERROR: " . $err->string ; | |
$cv->send; | |
}, | |
); | |
$client->start; | |
$cv->recv; | |
say "THE END"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment