2

CPAN上有Net::Msmgr模块。它写得很干净,乍一看代码看起来很可靠。然而,这个模块似乎是 beta 版,文档很少,也没有测试:-/

有人在生产中使用过这个模块吗?我现在还没有设法让它运行,因为它需要在应用程序中完成所有事件循环处理,而且正如我已经说过的那样,几乎没有文档,也没有工作示例可供研究。

这就是我到目前为止所去过的地方:

#!/usr/bin/perl
use strict;
use warnings;

use Event;
use Net::Msmgr::Object;
use Net::Msmgr::Session;
use Net::Msmgr::User;

use constant DEBUG => 511;
use constant EVENT_TIMEOUT => 5; # seconds

my ($username, $password) = qw/my.username@live.com my.password/;
my $buddy = 'your.username@live.com';

my $user = Net::Msmgr::User->new(user => $username, password => $password);
my $session = Net::Msmgr::Session->new;
$session->debug(DEBUG);
$session->login_handler(\&login_handler);
$session->user($user);

my $conv;

sub login_handler {
    my $self = shift;
    print "LOGIN\n";
    $self->ui_state_nln;
    $conv = $session->ui_new_conversation;
    $conv->invite($buddy);
}

our %watcher;

sub ConnectHandler {
    my ($connection) = @_;
    warn "CONNECT\n";
    my $socket = $connection->socket;
    $watcher{$connection} = Event->io(fd => $socket,
                                      cb => [ $connection, '_recv_message' ],
                                      poll => 're',
                                      desc => 'recv_watcher',
                                      repeat => 1);
}

sub DisconnectHandler {
    my $connection = shift;
    print "DISCONNECT\n";
    $watcher{$connection}->cancel;
}

$session->connect_handler(\&ConnectHandler);
$session->disconnect_handler(\&DisconnectHandler);

$session->Login;

Event::loop();

这就是它的输出:

Dispatch Server connecting to: messenger.hotmail.com:1863
Dispatch Server connected
CONNECT
Dispatch Server >>>VER 1 MSNP2 CVR0
--> VER 1 MSNP2 CVR0
Dispatch Server >>>USR 2 MD5 I my.username@live.com
--> USR 2 MD5 I my.username@live.com
Dispatch Server <<<VER 1 CVR0
<-- VER 1 CVR0

就是这样,它挂在这里。未触发登录处理程序。我究竟做错了什么?

4

1 回答 1

-2

希望这些文件能帮到你

1) Net::Msmgr 文档

2)网络::Msmgr::会话

于 2010-04-26T09:03:13.763 回答