NAME
Net::WebSocket::Streamer - Send a stream easily over WebSocket
SYNOPSIS
Here’s the gist of it:
my $streamer = Net::WebSocket::Streamer->new('binary');
my $frame = $streamer->create_chunk($buf);
my $last_frame = $streamer->create_final($buf);
… but a more complete example might be this: streaming a file of arbitrary size in 64-KiB chunks:
my $size = -s $rfh;
while ( read $rfh, my $buf, 65536 ) {
my $frame;
if (tell($rfh) == $size) {
$frame = $streamer->create_final($buf);
}
else {
$frame = $streamer->create_chunk($buf);
}
syswrite $wfh, $frame->to_bytes();
}
You can, of course, create/send an empty final frame for cases where you’re not sure how much data will actually be sent.
EXTENSION SUPPORT
To stream custom frame types (or overridden classes), you can subclass this module and define frame_class_*
constants, where *
is the frame type, e.g., text
, binary
.