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
new
Protocol::WebSocket::Frame->new('data'); # same as (buffer => '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.
When called with more than one arguments, it takes the following named arguments (all of them are optional).
buffer
""
The payload of the frame.
type
"text"
The type of the frame. Accepted values are:
continuation text binary ping pong close
opcode
The opcode of the frame. If type field is set to a valid string, this field is ignored.
fin
"fin" flag of the frame. "fin" flag must be 1 in the ending frame of fragments.
masked
If set to true, the frame will be masked.
version
'draft-ietf-hybi-17'
WebSocket protocol version string. See Protocol::WebSocket for valid version strings.
is_continuation
Check if frame is of continuation type.
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.
$opcode = $frame->opcode; $frame->opcode(8);
Get/set opcode of the frame.
append
$frame->append($chunk);
Append a frame chunk.
Beware that this method is destructive. It makes $chunk empty unless $chunk is read-only.
$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.