WebSocket::Frame - WebSocket Frame
use WebSocket::Frame; # Create frame my $frame = WebSocket::Frame->new( '123' ); $frame->to_bytes; # Parse frames my $frame = WebSocket::Frame->new; $frame->append( $some_data ); $f->next; # get next message $f->next; # get another next message
v0.1.0
Construct or parse a WebSocket frame.
new
# same as (buffer => 'data') WebSocket::Frame->new( 'data' ); WebSocket::Frame->new( buffer => 'data', type => 'close' );
Create a new WebSocket::Frame instance. Automatically detect if the passed data is a Perl string (UTF-8 flag) 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. It can also be provided as the first argument of the "new" method.
fin
Boolean default to 1. Indicate whether this frame is the last frame of the entire message body
fin flag of the frame. fin flag must be 1 in the ending frame of fragments.
masked
Boolean default to 0.
If set to true, the frame will be masked.
opcode
Default to 1. Operation bit, which defines the type of this frame
The opcode of the frame. If type field is set to a valid string, this field is ignored.
rsv
Reserved bit, must be 0, if it is not 0, it is marked as connection failure
type
Default to text
text
The type of the frame. Accepted values are: continuation, text, binary, ping, pong, close
continuation
binary
ping
pong
close
version
String. Default to draft-ietf-hybi-17
draft-ietf-hybi-17
WebSocket protocol version string. See WebSocket for valid version strings.
$frame->append( $chunk );
Append a frame chunk.
Beware that this method is destructive. It makes $chunk empty unless $chunk is read-only.
$chunk
Indicate whether this frame is the last frame of the entire message body
Sets or gets the array object of payload fragments
Returns true if frame is of binary type, false otherwise.
Returns true if frame is of close type, false otherwise.
Returns true if frame is of continuation type, false otherwise.
Returns true if frame is a ping request, false otherwise.
Returns true if frame is a pong response, false otherwise.
Returns true if frame is of text type, false otherwise.
Indicate whether the carried content needs to be XORed with a mask
$masked = $frame->masked; $frame->masked(1);
Get or set masking of the frame.
The maximum fragments allowed.
The maximum size of the payload. You may set this to 0 (but not undef) to disable checking the payload size.
0
$frame->append( $some_data ); $frame->next; # next message
Return the next message as a Perl string (UTF-8 decoded).
Return the next message as is.
$opcode = $frame->opcode; $frame->opcode(8);
Get or set opcode of the frame. Operation bit, which defines the type of this frame.
Provided a type and this returns true if it is supported, false otherwise. This is case insensitive.
Without any argument, this returns an array object of supported frame types.
Construct a WebSocket message.
Viacheslav Tykhanovskyi for code borrowed.
Jacques Deguest <jack@deguest.jp>
WebSocket::Client, WebSocket::Connection, WebSocket::Server
Copyright(c) 2021-2023 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.
To install WebSocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WebSocket
CPAN shell
perl -MCPAN -e shell install WebSocket
For more information on module installation, please visit the detailed CPAN module installation guide.