JRuDevels

Jabber Russian Developers Forum.
Log in Register FAQ Memberlist Search JRuDevels Forum Index

JRuDevels Forum Index » Разработка и проектирование [Devel] » Simle Jabber client on Perl
Post new topic  Reply to topic View previous topic :: View next topic 
Simle Jabber client on Perl
PostPosted: Wed Aug 15, 2007 11:05 am Reply with quote
bimax
Guest




Всем добрый день.

Переискал кучу доков... Может чего не осилил, подскажите плиз как написать джабер клиент чтоб оно просто при запуске авторизировался на сервере и отсылал одному поределённому пользователю сообщение "Hello world!". И потом отключался.

Спасибо.
PostPosted: Fri Aug 17, 2007 6:33 pm Reply with quote
ikd
Отметившийся
Отметившийся
Joined: 18 May 2007
Posts: 16




проще некуда:

Code:
:#! /usr/bin/perl

use strict;
use warnings;

use Net::XMPP;

my $hostName = '';
my $portNumber = 5222;
my $componentName = '';
my $userName = '';
my $passWord = '';
my $resource = 'bot';
my $tls = 0;
my $connectionType = 'tcpip';

my $debugLevel = 0;

my $bot = new Net::XMPP::Client(debuglevel => $debugLevel);

$bot->SetCallBacks(
onconnect => \&connectedCB,
onauth => \&authedCB,
ondisconnect => \&disconnectedCB,
);

$bot->SetMessageCallBacks(
chat => \&messageCB,
);

$bot->Execute(
hostname => $hostName,
port => $portNumber,
tls => $tls,
username => $userName,
password => $passWord,
resource => $resource,
register => 0,
connectiontype => $connectionType,
);

sub messageCB {
my $sid = shift;
my $msg = shift;

my $from = $msg->GetFrom;
my $to = $msg->GetTo;

my $name;
my $data;

print "From : ", $from, "\n",
"Subject : ", $msg->GetSubject, "\n",
$msg->GetBody, "\n";

$name = $msg->GetBody;

$data = $msg->GetBody;

print ">>$name\n";
print $data, "\n";

$bot->MessageSend(
to => $from,
from => $to,
resource => '',
type => $msg->GetType,
subject => $msg->GetSubject,
body => $data,
);

}

sub connectedCB {
print "Connected\n";
}

sub authedCB {
print "Authed\n";
$bot->PresenceSend;
}

sub disconnectedCB {
print "Disconnected\n";
}


Логинится. Принимает сообщение, отправляет его обратно.
View user's profile Send private message
Simle Jabber client on Perl
JRuDevels Forum Index » Разработка и проектирование [Devel]
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT + 3 Hours  
Page 1 of 1  

  
  
 Post new topic  Reply to topic  


Powered by phpBB © 2001-2004 phpBB Group
phpBB Style by Vjacheslav Trushkin