[JDEV] Proper use of Perl Net::Jabber calls

rebbaj rebbaj rebbaj2000 at yahoo.co.uk
Tue Jan 7 08:55:42 CST 2003


Hello jabber people.

I am hoping that someone can help me out with how the Perl Net::Jabber library should be used.  Note that I am also somewhat new to perl so if I get confused by some of the syntax, you will have to excuse me.  The examples in the Oreily book were rather helpful but I seem to be having problems in calling and receiving IQ information.

Here is what I am trying to send and receive in XML:

SENT:
<iq id="jcl_9" type="get">
    <query xmlns="jabber:iq:roster"/>
</iq>

RECV:
<iq from='rebbaj at jabber.org/Perl' id='jcl_9' type='result'>
  <query xmlns='jabber:iq:roster'>
    <item jid='rebbaj at jabber.com' name='rebbaj' subscription='both'/>
    <item jid='rebbaj2 at jabber.com' name='rebbaj2' subscription='both'/>
  </query>
</iq>

The code stub that I have written to do this is as follows.  I suspect that I have the flow a bit wrong and I am not using the optimal calls to parse the resulting returned roster data...  Any help would be appreciated....

rebbaj

------------------------------------------------
#!/usr/bin/perl
use Net::Jabber qw(Client);
use strict;
my $c=Net::Jabber::Client->new();
$c->Connect('hostname'=> 'jabber.org', 'port'=>5222);

$c->AuthSend('username'=> 'rebbaj',
      'password'=> 'secret',
      'resource'=> 'Perl');

$c->SetCallBacks('presence'=> \&handle_presence);
$c->SetCallBacks('iq'=> \&handle_iq);
$c->PresenceSend();

My $IQ = new Net::Jabber::IQ();
$IQ->NewQuery("jabber:iq:roster");  # Does this actually make the IQ get request?$c->Send($IQ); # is this call necessary?

print "involking process\n";
$c->Process();

 

 


$c->Disconnect;
exit(0);

sub handle_presence {
 my ($sid, $presence) = @_;

 my $show = $presence->GetShow() || 'online';
 
 print "presence packet received $show\n";
}

sub handle_iq {
 my ($sid, $iq) = @_;

 my $querytag = $iq->GetQuery();

 
 print "iq packet received $querytag\n";
}

 




---------------------------------
With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.jabber.org/jdev/attachments/20030107/95e67efe/attachment-0002.htm>


More information about the JDev mailing list