当我尝试进行身份验证时,为什么Perl的Net :: Msmgr会挂起?

时间:2010-04-26 08:49:52

标签: perl event-handling windows-live-messenger

CPAN上有Net::Msmgr个模块。它写得很干净,代码看起来很值得信赖。然而,这个模块似乎是测试版,几乎没有文档和测试: - /

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

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

#!/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

就是这样,这里挂了。登录时的处理程序未被触发。我做错了什么?

1 个答案:

答案 0 :(得分:-2)

希望这些文件可以帮助你

1)Net::Msmgr documentation

2)Net::Msmgr::Session