1Protocol::WebSocket::FrUasmeer(3Cpomn)tributed Perl DocuPmreonttoactoilo:n:WebSocket::Frame(3pm)
2
3
4
6 Protocol::WebSocket::Frame - WebSocket Frame
7
9 # Create frame
10 my $frame = Protocol::WebSocket::Frame->new('123');
11 $frame->to_bytes;
12
13 # Parse frames
14 my $frame = Protocol::WebSocket::Frame->new;
15 $frame->append(...);
16 $f->next; # get next message
17 $f->next; # get another next message
18
20 Construct or parse a WebSocket frame.
21
23 By default built-in "rand" is used, this is not secure, so when
24 Math::Random::Secure is installed it is used instead.
25
27 "new"
28 Protocol::WebSocket::Frame->new('data'); # same as (buffer => 'data')
29 Protocol::WebSocket::Frame->new(buffer => 'data', type => 'close');
30
31 Create a new Protocol::WebSocket::Frame instance. Automatically detect
32 if the passed data is a Perl string (UTF-8 flag) or bytes.
33
34 When called with more than one arguments, it takes the following named
35 arguments (all of them are optional).
36
37 "buffer" => STR (default: "")
38 The payload of the frame.
39
40 "type" => TYPE_STR (default: "text")
41 The type of the frame. Accepted values are:
42
43 continuation
44 text
45 binary
46 ping
47 pong
48 close
49
50 "opcode" => INT (default: 1)
51 The opcode of the frame. If "type" field is set to a valid string,
52 this field is ignored.
53
54 "fin" => BOOL (default: 1)
55 "fin" flag of the frame. "fin" flag must be 1 in the ending frame
56 of fragments.
57
58 "masked" => BOOL (default: 0)
59 If set to true, the frame will be masked.
60
61 "version" => VERSION_STR (default: 'draft-ietf-hybi-17')
62 WebSocket protocol version string. See Protocol::WebSocket for
63 valid version strings.
64
65 "is_continuation"
66 Check if frame is of continuation type.
67
68 "is_text"
69 Check if frame is of text type.
70
71 "is_binary"
72 Check if frame is of binary type.
73
74 "is_ping"
75 Check if frame is a ping request.
76
77 "is_pong"
78 Check if frame is a pong response.
79
80 "is_close"
81 Check if frame is of close type.
82
83 "opcode"
84 $opcode = $frame->opcode;
85 $frame->opcode(8);
86
87 Get/set opcode of the frame.
88
89 "masked"
90 $masked = $frame->masked;
91 $frame->masked(1);
92
93 Get/set masking of the frame.
94
95 "append"
96 $frame->append($chunk);
97
98 Append a frame chunk.
99
100 Beware that this method is destructive. It makes $chunk empty unless
101 $chunk is read-only.
102
103 "next"
104 $frame->append(...);
105
106 $frame->next; # next message
107
108 Return the next message as a Perl string (UTF-8 decoded).
109
110 "next_bytes"
111 Return the next message as is.
112
113 "to_bytes"
114 Construct a WebSocket message.
115
116 "max_payload_size"
117 The maximum size of the payload. You may set this to 0 or "undef" to
118 disable checking the payload size.
119
120
121
122perl v5.32.1 2021-01-27 Protocol::WebSocket::Frame(3pm)