.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Mojo::WebSocket 3"
.TH Mojo::WebSocket 3 "2023-03-08" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Mojo::WebSocket \- The WebSocket protocol
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Mojo::WebSocket qw(WS_TEXT build_frame parse_frame);
\&
\& my $bytes = build_frame 0, 1, 0, 0, 0, WS_TEXT, \*(AqHello World!\*(Aq;
\& my $frame = parse_frame \e$bytes, 262144;
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Mojo::WebSocket implements the WebSocket protocol as described in \s-1RFC 6455\s0 <https://tools.ietf.org/html/rfc6455>.
Note that 64\-bit frames require a Perl with support for quads or they are limited to 32\-bit.
.SH "FUNCTIONS"
.IX Header "FUNCTIONS"
Mojo::WebSocket implements the following functions, which can be imported individually.
.SS "build_frame"
.IX Subsection "build_frame"
.Vb 1
\& my $bytes = build_frame $masked, $fin, $rsv1, $rsv2, $rsv3, $op, $payload;
.Ve
.PP
Build WebSocket frame.
.PP
.Vb 2
\& # Masked binary frame with FIN bit and payload
\& say build_frame 1, 1, 0, 0, 0, WS_BINARY, \*(AqHello World!\*(Aq;
\&
\& # Text frame with payload but without FIN bit
\& say build_frame 0, 0, 0, 0, 0, WS_TEXT, \*(AqHello \*(Aq;
\&
\& # Continuation frame with FIN bit and payload
\& say build_frame 0, 1, 0, 0, 0, WS_CONTINUATION, \*(AqWorld!\*(Aq;
\&
\& # Close frame with FIN bit and without payload
\& say build_frame 0, 1, 0, 0, 0, WS_CLOSE, \*(Aq\*(Aq;
\&
\& # Ping frame with FIN bit and payload
\& say build_frame 0, 1, 0, 0, 0, WS_PING, \*(AqTest 123\*(Aq;
\&
\& # Pong frame with FIN bit and payload
\& say build_frame 0, 1, 0, 0, 0, WS_PONG, \*(AqTest 123\*(Aq;
.Ve
.SS "challenge"
.IX Subsection "challenge"
.Vb 1
\& my $bool = challenge Mojo::Transaction::WebSocket\->new;
.Ve
.PP
Check WebSocket handshake challenge.
.SS "client_handshake"
.IX Subsection "client_handshake"
.Vb 1
\& my $tx = client_handshake Mojo::Transaction::HTTP\->new;
.Ve
.PP
Perform WebSocket handshake client-side.
.SS "parse_frame"
.IX Subsection "parse_frame"
.Vb 1
\& my $frame = parse_frame \e$bytes, $limit;
.Ve
.PP
Parse WebSocket frame.
.PP
.Vb 8
\& # Parse single frame and remove it from buffer
\& my $frame = parse_frame \e$buffer, 262144;
\& say "FIN: $frame\->[0]";
\& say "RSV1: $frame\->[1]";
\& say "RSV2: $frame\->[2]";
\& say "RSV3: $frame\->[3]";
\& say "Opcode: $frame\->[4]";
\& say "Payload: $frame\->[5]";
.Ve
.SS "server_handshake"
.IX Subsection "server_handshake"
.Vb 1
\& my $tx = server_handshake Mojo::Transaction::HTTP\->new;
.Ve
.PP
Perform WebSocket handshake server-side.
.SH "CONSTANTS"
.IX Header "CONSTANTS"
Mojo::WebSocket implements the following constants, which can be imported individually.
.SS "\s-1WS_BINARY\s0"
.IX Subsection "WS_BINARY"
Opcode for \f(CW\*(C`Binary\*(C'\fR frames.
.SS "\s-1WS_CLOSE\s0"
.IX Subsection "WS_CLOSE"
Opcode for \f(CW\*(C`Close\*(C'\fR frames.
.SS "\s-1WS_CONTINUATION\s0"
.IX Subsection "WS_CONTINUATION"
Opcode for \f(CW\*(C`Continuation\*(C'\fR frames.
.SS "\s-1WS_PING\s0"
.IX Subsection "WS_PING"
Opcode for \f(CW\*(C`Ping\*(C'\fR frames.
.SS "\s-1WS_PONG\s0"
.IX Subsection "WS_PONG"
Opcode for \f(CW\*(C`Pong\*(C'\fR frames.
.SS "\s-1WS_TEXT\s0"
.IX Subsection "WS_TEXT"
Opcode for \f(CW\*(C`Text\*(C'\fR frames.
.SH "DEBUGGING"
.IX Header "DEBUGGING"
You can set the \f(CW\*(C`MOJO_WEBSOCKET_DEBUG\*(C'\fR environment variable to get some advanced diagnostics information printed to
\&\f(CW\*(C`STDERR\*(C'\fR.
.PP
.Vb 1
\& MOJO_WEBSOCKET_DEBUG=1
.Ve
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.