我正在尝试用Perl编写一个简单的WebSocket客户端:
use Protocol::WebSocket::Client;
my $client = Protocol::WebSocket->new(url => 'ws://myserver:port');
# Sends a correct handshake header
$client->connect;
# Register on connect handler
$client->on(
connect => sub {
$client->write('hi there');
}
);
# Parses incoming data and on every frame calls on_read
$client->read($reply);
print "$reply\n";
# Sends correct close header
$client->disconnect;
正如
Protocol::WebSocket::Client
的文档所示,但我收到了以下消息:Can't locate object method "new" via package "Protocol::WebSocket" at ./webSocketClient.pl.
我做错了什么?