Protocol::WebSocket::Client - WebSocket client
my $sock = ...get non-blocking socket...;
my $client = Protocol::WebSocket->new(url => 'ws://localhost:3000');
$client->on(
write => sub {
my $client = shift;
my ($buf) = @_;
syswrite $sock, $buf;
}
);
$client->on(
read => sub {
my $client = shift;
my ($buf) = @_;
...do smth with read data...
}
);
# 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(...data from socket...);
# Sends correct close header
$client->disconnect;
Protocol::WebSocket::Client is a convenient class for writing a WebSocket
client.