ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-XMPP2/samples/test
Revision: 1.3
Committed: Tue Jan 23 22:57:22 2007 UTC (19 years, 8 months ago) by elmex
Branch: MAIN
Changes since 1.2: +3 -3 lines
Log Message:
more testing, fixed typo :-)

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 elmex 1.2 username => 'elmex', #'elmor',
18 elmex 1.3 domain => 'localhost',#amessage.eu',#'jabber.org',
19 elmex 1.1 resource => $res,
20     password => 'xxxxxx',
21     );
22 elmex 1.2 $con->connect or die "Couldn't connect: $!";
23 elmex 1.1 $con->init;
24     $con->reg_cb (
25     session_ready => sub {
26     my ($con) = @_;
27     print "stream ready!\n" ;
28     $con->send_iq (
29     get => sub {
30     my ($w) = @_;
31     $w->addPrefix (xmpp_ns ('version'), '');
32     $w->emptyTag ([xmpp_ns ('version'), 'query']);
33     }, sub {
34     my ($node, $errnode, $err) = @_;
35     unless (defined $node) {
36     print "ERROR: $err->[0]/$err->[3]:" .($err->[1]->name)."\n";
37     return;
38     }
39     my (@name) = $node->find_all ([qw/version query/], [qw/version name/]);
40     my (@ver) = $node->find_all ([qw/version query/], [qw/version version/]);
41     print "REPL: ".($name[0]->text). " " .($ver[0]->text)."!\n" if @name and @ver;
42     print "NO VERSION FOUND!\n" unless @name and @ver;
43     },
44 elmex 1.2 to => $con->{domain},#'localhost',
45 elmex 1.1 from => $con->jid
46     );
47     },
48 elmex 1.3 debug_recv => sub { print "recv: $_[1]\n"; 1 },
49     debug_send => sub { print "send: $_[1]\n"; 1 },
50 elmex 1.1 stream_error => sub { die "ERROR[$_[1]]{$_[2]}\n" },
51     );
52    
53    
54     $j->wait;