[JDEV] Perl Programming Examples

Tiago Almeida tiago.almeida at co.clix.pt
Mon Jan 5 08:13:36 CST 2004


Hi,
you can use Net::Jabber and all of is bundle, it should be
self-explanatory.

anyway take also a look at :
http://www.jabberstudio.org/cgi-bin/viewcvs.cgi/*checkout*/chatbot/chatbot?content-type=text%2Fplain&rev=1.51


or if it is for a simple use try this:

#! /usr/bin/perl

 use Net::Jabber qw (Client);
 use vars qw/%presence/;
 use XML::Simple;
 use strict;

 use constant SERVER    => 'jabber server';  # Jabber server to connect
to
 use constant PORT      => jabber server port;          # Port to
connect to
 use constant USER      => 'jabber username';      # user this script
connects as
 use constant PASSWORD  => 'jabber pwd';    # password associated with
USER
 use constant RESOURCE  => 'perlscript';


 my $Con = new Net::Jabber::Client();
 $Con ->Connect("hostname" => SERVER) or die"\n$@\n";

 my @result = $Con ->AuthSend(
       "username" => USER,
       "password" => PASSWORD,
       "resource" => RESOURCE
 );

 $Con->SetCallBacks("message" => \&handle_message);
 $Con->PresenceSend();


 sub handle_message {
        shift;
        my $foo = new Net::Jabber::Message(@_);
        my $from = $foo->GetFrom();
        my $JID = new Net::Jabber::JID($from);
        my $userid   = $JID->GetUserID();
        my $msg_get = shift;
# if the message is offline it will be ignored 
        return if(defined($msg_get->{CHILDREN}->{x}));
        my $MSG = $msg_get->GetBody();
        my $texto = $MSG;
        my $clixid;
        return if(!defined($MSG));
        print "\n$MSG\n";

        my $msg = Net::Jabber::Message->new();
       $msg->SetMessage( "to" => $userid."\@jabber server hostname",
                         "body" => $texto);
       $Con->Send($msg);
 }

 while (1) { $Con->Process(1) }

regards,

Tiago Almeida


On Mon, 2004-01-05 at 13:47, Rajkumar S wrote:
> Hi,
> 
> Any one with some perl example of how to receive messaged using perl? I 
> have the send part working nicely.
> 
> raj
> _______________________________________________
> jdev mailing list
> jdev at jabber.org
> http://mailman.jabber.org/listinfo/jdev




More information about the JDev mailing list