Protocol::WebSocket::Frame - WebSocket Frame
# Create frame my $frame = Protocol::WebSocket::Frame->new('123'); $frame->to_bytes; # Parse frames my $frame = Protocol::WebSocket::Frame->new; $frame->append(...); $f->next; # get next message $f->next; # get another next message
Construct or parse a WebSocket frame.
By default built-in rand is used, this is not secure, so when Math::Random::Secure is installed it is used instead.
rand
type
Frame's type. text by default. Other accepted values:
text
binary ping pong close
new
Protocol::WebSocket::Frame->new('data'); Protocol::WebSocket::Frame->new(buffer => 'data', type => 'close');
Create a new Protocol::WebSocket::Frame instance. Automatically detect if the passed data is a Perl string or bytes.
is_text
Check if frame is of text type.
is_binary
Check if frame is of binary type.
is_ping
Check if frame is a ping request.
is_pong
Check if frame is a pong response.
is_close
Check if frame is of close type.
append
$frame->append(...);
Append a frame chunk.
next
$frame->append(...); $frame->next; # next message
Return the next message as a Perl string.
next_bytes
Return the next message as a UTF-8 encoded string.
to_bytes
Construct a WebSocket message as a UTF-8 encoded string.
To install Protocol::WebSocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Protocol::WebSocket
CPAN shell
perl -MCPAN -e shell install Protocol::WebSocket
For more information on module installation, please visit the detailed CPAN module installation guide.