连接到网络套接字时"handshake error: Wrong response line"



我正试图用以下Perl代码连接到一个websocket:

use AnyEvent;
use AnyEvent::WebSocket::Client 0.12;
my $client = AnyEvent::WebSocket::Client->new;
$client->connect("wss://example.com")->cb(sub {
    my $connection = eval { shift->recv };  # This line is generating the error
    if($@) {
        # handle error...
        warn $@;
        return;
    }
    # send a message through the websocket...
    $connection->send('');
    # receive message from the websocket...
    $connection->on(each_message => sub {
        my($connection, $message) = @_;
        print "Recieved Message...n"
    });
    # handle a closed connection...
    $connection->on(finish => sub {
        # $connection is the same connection object
        my($connection) = @_;
        print "Disconnected...n";
    });
$connection->close;
});
AnyEvent->condvar->recv;

然而,我得到以下错误:

handshake error: Wrong response line at websocket.pl line 10.

如何修复此错误?


顺便说一句,我想做的是将以下工作node.js代码移植到Perl:

var autobahn = require('autobahn');
var wsuri = "wss://example.com";
var connection = new autobahn.Connection({
    url: wsuri,
    realm: "realm1"
});
connection.onopen = function (session) {
    function txtEvent (args,kwargs) {
        console.log(args);
    };
    session.subscribe('textmsg', txtEvent);
}
connection.onclose = function () {
    console.log("Connection closed");
}
connection.open();

我还在复习关于Perl套接字编程的教程。

任何调试它的帮助,或者关于我应该使用哪个包(而不是AnyEvent::WebSocket::Client)进行连接的建议都会很有帮助。

错误消息看起来像是SSL握手问题。(websocket使用wss)。证书是否可信?您可以添加以下内容:

# Ignore SSL verification issues
$client->{ssl_no_verify} = 1;

我在我的websocket上测试了你的代码,它有效。(没有错误消息)。

相关内容

  • 没有找到相关文章

最新更新