Net::WebSocket::Streamer::Server
open my $rfh, '<', '/some/big/file'; my $stream = Net::WebSocket::Streamer::Server->new('binary'); while ( read $rfh, my $buf, 32768 ) { my $chunk = $stream->create_chunk($buf); print {$socket} $chunk->to_bytes(); } print {$socket} $stream->create_final(q<>);
The SYNOPSIS pretty well shows it: you can use this module (or its twin, Net::WebSocket::Streamer::Client) to send a WebSocket message without buffering the full contents.
Net::WebSocket::Streamer::Client
You can subclass this module to support initial frame types other than text or binary. (Subsequent frames are always continuations.)
You can also set the reserved bytes manually on the individual frames to support extensions that involve those bits.
To install Net::WebSocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::WebSocket
CPAN shell
perl -MCPAN -e shell install Net::WebSocket
For more information on module installation, please visit the detailed CPAN module installation guide.