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

Yanming Xiao xiao at legatovideo.com
Wed Jan 8 09:23:20 CST 2003


Rebbaj,

Sorry for my rush answer. After taking a look again at my code, 
I understand your problem this time. 

I found the following comment in my code.

#   this step is important --- to behavior as a regualr Jabber client.  
#
    %roster = $Connection->RosterGet();

I recalled the reason I wrote this comment here: "RosterGet()" is used to make a web client behaving like a regular Jabber client such as Exodus for Windows. Otherwise, 
you will not get a correct result by sending an IQ packet. That is what I found when I 
debugging my code. 

if you comment this line in the code segment I sent in my previous, the following 
IQ packet sending to the server would NOT give you a right result. 

-Yanming



----- Original Message ----- 
  From: rebbaj rebbaj 
  To: jdev at jabber.org 
  Sent: Tuesday, January 07, 2003 5:39 PM
  Subject: Re: [JDEV] Proper use of Perl Net::Jabber calls


  Thanks Yanming.  I took a good long look at the code found at http://www.jabberstudio.org/cgi-bin/viewcvs.cgi/*checkout*/netjabber/examples/client.pl?rev=1.4&content-type=text/plain 

  What I still do not understand is why the $Connection->RosterGet(); call does not result in all of the roster entries being sent back from the server and hence triggering the sub InIQ routine.  If I manually enter the following XML "<iq type="get"><query xmlns="jabber:iq:roster"/></iq>, I get all the entries back. 

  The docs state "RosterGet() - sends an empty Net::Jabber::IQ::Roster tag to the server so the server will send the Roster to the client." 

  Any other ideas? 

  Regards, 

  Rebbaj 

   Yanming Xiao <xiao at legatovideo.com> wrote: 

    Rabbaj,

    It seems to me that you are using 2 different packages.  

    There is a function called "RosterGet()" in Net::Jabber::Client. 
    find the sample code in:
    http://jru.jabberstudio.org/


    -Yanming
      ----- Original Message ----- 
      From: rebbaj rebbaj 
      To: jdev at jabber.org 
      Sent: Tuesday, January 07, 2003 9:40 AM
      Subject: [JDEV] Proper use of Perl Net::Jabber calls


      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






------------------------------------------------------------------------------
  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/20030108/9311aa96/attachment-0002.htm>


More information about the JDev mailing list