ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-XMPP2/samples/test
Revision: 1.1
Committed: Tue Jan 23 15:56:47 2007 UTC (19 years, 8 months ago) by elmex
Branch: MAIN
Log Message:
initial checkin.

File Contents

# User Rev Content
1 elmex 1.1 #!/opt/perl/bin/perl
2     use strict;
3     use utf8;
4     use AnyEvent;
5     use Net::XMPP2::IM::Connection;
6     use Net::XMPP2::Namespaces qw/xmpp_ns/;
7     use Net::LibIDN qw/idn_prep_resource/;
8     use Encode;
9    
10     binmode STDOUT, ":utf8";
11    
12     my $j = AnyEvent->condvar;
13    
14     my $res = "Net::XどなPP2";
15    
16     my $con = Net::XMPP2::IM::Connection->new (
17     username => 'ELmex',
18     domain => 'localhost',
19     resource => $res,
20     password => 'xxxxxx',
21     );
22     if ($con->connect) {
23     print "CONNECT!\n";
24     } else {
25     print "UNABLETO CONNECT: $!\n";
26     }
27     $con->init;
28     $con->reg_cb (
29     session_ready => sub {
30     my ($con) = @_;
31     print "stream ready!\n" ;
32     $con->send_iq (
33     get => sub {
34     my ($w) = @_;
35     $w->addPrefix (xmpp_ns ('version'), '');
36     $w->emptyTag ([xmpp_ns ('version'), 'query']);
37     }, sub {
38     my ($node, $errnode, $err) = @_;
39     unless (defined $node) {
40     print "ERROR: $err->[0]/$err->[3]:" .($err->[1]->name)."\n";
41     return;
42     }
43     my (@name) = $node->find_all ([qw/version query/], [qw/version name/]);
44     my (@ver) = $node->find_all ([qw/version query/], [qw/version version/]);
45     print "REPL: ".($name[0]->text). " " .($ver[0]->text)."!\n" if @name and @ver;
46     print "NO VERSION FOUND!\n" unless @name and @ver;
47     },
48     to => 'localhost',
49     from => $con->jid
50     );
51     },
52     debug_recv => sub { print "recv: $_[1]\n" },
53     debug_send => sub { print "send: $_[1]\n" },
54     stream_error => sub { die "ERROR[$_[1]]{$_[2]}\n" },
55     );
56    
57    
58     $j->wait;