Skip to content

Instantly share code, notes, and snippets.

@sugar84
Created September 8, 2012 20:00
Show Gist options
  • Save sugar84/3679238 to your computer and use it in GitHub Desktop.
Save sugar84/3679238 to your computer and use it in GitHub Desktop.
AnyEvent::XMPP
#!/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('test_acc@somewhere.net', 'password');
my $timer;
$client->reg_cb(
session_ready => sub {
my ($client, $acc) = @_;
$client->send_message(
"Hello! Jabber message!", 'recipient@anydomain.net',
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