.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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" '' '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 turned on, 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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mojo::Transaction::WebSocket 3pm" .TH Mojo::Transaction::WebSocket 3pm "2012-09-05" "perl v5.14.2" "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::Transaction::WebSocket \- WebSocket transaction container .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Transaction::WebSocket; \& \& my $ws = Mojo::Transaction::WebSocket\->new; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Transaction::WebSocket is a container for WebSocket transactions as described in \s-1RFC\s0 6455. Note that 64bit frames require a Perl with 64bit integer support, or they are limited to 32bit. .SH "EVENTS" .IX Header "EVENTS" Mojo::Transaction::WebSocket inherits all events from Mojo::Transaction and can emit the following new ones. .ie n .SS """drain""" .el .SS "\f(CWdrain\fP" .IX Subsection "drain" .Vb 4 \& $ws\->on(drain => sub { \& my $ws = shift; \& ... \& }); .Ve .PP Emitted once all data has been sent. .PP .Vb 4 \& $ws\->on(drain => sub { \& my $ws = shift; \& $ws\->send(time); \& }); .Ve .ie n .SS """frame""" .el .SS "\f(CWframe\fP" .IX Subsection "frame" .Vb 4 \& $ws\->on(frame => sub { \& my ($ws, $frame) = @_; \& ... \& }); .Ve .PP Emitted when a WebSocket frame has been received. .PP .Vb 10 \& $ws\->unsubscribe(\*(Aqframe\*(Aq); \& $ws\->on(frame => sub { \& my ($ws, $frame) = @_; \& 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 .ie n .SS """message""" .el .SS "\f(CWmessage\fP" .IX Subsection "message" .Vb 4 \& $ws\->on(message => sub { \& my ($ws, $message) = @_; \& ... \& }); .Ve .PP Emitted when a complete WebSocket message has been received. .PP .Vb 4 \& $ws\->on(message => sub { \& my ($ws, $message) = @_; \& say "Message: $message"; \& }); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Transaction::WebSocket inherits all attributes from Mojo::Transaction and implements the following new ones. .ie n .SS """handshake""" .el .SS "\f(CWhandshake\fP" .IX Subsection "handshake" .Vb 2 \& my $handshake = $ws\->handshake; \& $ws = $ws\->handshake(Mojo::Transaction::HTTP\->new); .Ve .PP The original handshake transaction, defaults to a Mojo::Transaction::HTTP object. .ie n .SS """masked""" .el .SS "\f(CWmasked\fP" .IX Subsection "masked" .Vb 2 \& my $masked = $ws\->masked; \& $ws = $ws\->masked(1); .Ve .PP Mask outgoing frames with \s-1XOR\s0 cipher and a random 32bit key. .ie n .SS """max_websocket_size""" .el .SS "\f(CWmax_websocket_size\fP" .IX Subsection "max_websocket_size" .Vb 2 \& my $size = $ws\->max_websocket_size; \& $ws = $ws\->max_websocket_size(1024); .Ve .PP Maximum WebSocket message size in bytes, defaults to the value of the \&\f(CW\*(C`MOJO_MAX_WEBSOCKET_SIZE\*(C'\fR environment variable or \f(CW262144\fR. .SH "METHODS" .IX Header "METHODS" Mojo::Transaction::WebSocket inherits all methods from Mojo::Transaction and implements the following new ones. .ie n .SS """new""" .el .SS "\f(CWnew\fP" .IX Subsection "new" .Vb 1 \& my $multi = Mojo::Content::MultiPart\->new; .Ve .PP Construct a new Mojo::Transaction::WebSocket object and subscribe to \&\f(CW\*(C`frame\*(C'\fR event with default message parser, which also handles \f(CW\*(C`PING\*(C'\fR and \&\f(CW\*(C`CLOSE\*(C'\fR frames automatically. .ie n .SS """build_frame""" .el .SS "\f(CWbuild_frame\fP" .IX Subsection "build_frame" .Vb 1 \& my $bytes = $ws\->build_frame($fin, $rsv1, $rsv2, $rsv3, $op, $payload); .Ve .PP Build WebSocket frame. .PP .Vb 2 \& # Continuation frame with FIN bit and payload \& say $ws\->build_frame(1, 0, 0, 0, 0, \*(AqWorld!\*(Aq); \& \& # Text frame with payload \& say $ws\->build_frame(0, 0, 0, 0, 1, \*(AqHello\*(Aq); \& \& # Binary frame with FIN bit and payload \& say $ws\->build_frame(1, 0, 0, 0, 2, \*(AqHello World!\*(Aq); \& \& # Close frame with FIN bit and without payload \& say $ws\->build_frame(1, 0, 0, 0, 8, \*(Aq\*(Aq); \& \& # Ping frame with FIN bit and payload \& say $ws\->build_frame(1, 0, 0, 0, 9, \*(AqTest 123\*(Aq); \& \& # Pong frame with FIN bit and payload \& say $ws\->build_frame(1, 0, 0, 0, 10, \*(AqTest 123\*(Aq); .Ve .ie n .SS """client_challenge""" .el .SS "\f(CWclient_challenge\fP" .IX Subsection "client_challenge" .Vb 1 \& my $success = $ws\->client_challenge; .Ve .PP Check WebSocket handshake challenge. .ie n .SS """client_handshake""" .el .SS "\f(CWclient_handshake\fP" .IX Subsection "client_handshake" .Vb 1 \& $ws\->client_handshake; .Ve .PP WebSocket handshake. .ie n .SS """client_read""" .el .SS "\f(CWclient_read\fP" .IX Subsection "client_read" .Vb 1 \& $ws\->client_read($data); .Ve .PP Read raw WebSocket data. .ie n .SS """client_write""" .el .SS "\f(CWclient_write\fP" .IX Subsection "client_write" .Vb 1 \& my $chunk = $ws\->client_write; .Ve .PP Raw WebSocket data to write. .ie n .SS """connection""" .el .SS "\f(CWconnection\fP" .IX Subsection "connection" .Vb 1 \& my $connection = $ws\->connection; .Ve .PP Alias for \*(L"connection\*(R" in Mojo::Transaction. .ie n .SS """finish""" .el .SS "\f(CWfinish\fP" .IX Subsection "finish" .Vb 1 \& $ws = $ws\->finish; .Ve .PP Finish the WebSocket connection gracefully. .ie n .SS """is_websocket""" .el .SS "\f(CWis_websocket\fP" .IX Subsection "is_websocket" .Vb 1 \& my $true = $ws\->is_websocket; .Ve .PP True. .ie n .SS """kept_alive""" .el .SS "\f(CWkept_alive\fP" .IX Subsection "kept_alive" .Vb 1 \& my $kept_alive = $ws\->kept_alive; .Ve .PP Alias for \*(L"kept_alive\*(R" in Mojo::Transaction. .ie n .SS """local_address""" .el .SS "\f(CWlocal_address\fP" .IX Subsection "local_address" .Vb 1 \& my $local_address = $ws\->local_address; .Ve .PP Alias for \*(L"local_address\*(R" in Mojo::Transaction. .ie n .SS """local_port""" .el .SS "\f(CWlocal_port\fP" .IX Subsection "local_port" .Vb 1 \& my $local_port = $ws\->local_port; .Ve .PP Alias for \*(L"local_port\*(R" in Mojo::Transaction. .ie n .SS """parse_frame""" .el .SS "\f(CWparse_frame\fP" .IX Subsection "parse_frame" .Vb 1 \& my $frame = $ws\->parse_frame(\e$bytes); .Ve .PP Parse WebSocket frame. .PP .Vb 8 \& # Parse single frame and remove it from buffer \& my $frame = $ws\->parse_frame(\e$buffer); \& 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 .ie n .SS """remote_address""" .el .SS "\f(CWremote_address\fP" .IX Subsection "remote_address" .Vb 1 \& my $remote_address = $ws\->remote_address; .Ve .PP Alias for \*(L"remote_address\*(R" in Mojo::Transaction. .ie n .SS """remote_port""" .el .SS "\f(CWremote_port\fP" .IX Subsection "remote_port" .Vb 1 \& my $remote_port = $ws\->remote_port; .Ve .PP Alias for \*(L"remote_port\*(R" in Mojo::Transaction. .ie n .SS """req""" .el .SS "\f(CWreq\fP" .IX Subsection "req" .Vb 1 \& my $req = $ws\->req; .Ve .PP Alias for \*(L"req\*(R" in Mojo::Transaction. .ie n .SS """res""" .el .SS "\f(CWres\fP" .IX Subsection "res" .Vb 1 \& my $res = $ws\->res; .Ve .PP Alias for \*(L"res\*(R" in Mojo::Transaction. .ie n .SS """resume""" .el .SS "\f(CWresume\fP" .IX Subsection "resume" .Vb 1 \& $ws = $ws\->resume; .Ve .PP Alias for \*(L"resume\*(R" in Mojo::Transaction. .ie n .SS """send""" .el .SS "\f(CWsend\fP" .IX Subsection "send" .Vb 5 \& $ws\->send({binary => $bytes}); \& $ws\->send({text => $bytes}); \& $ws\->send([$fin, $rsv1, $rsv2, $rsv3, $op, $payload]); \& $ws\->send(\*(AqHi there!\*(Aq); \& $ws\->send(\*(AqHi there!\*(Aq => sub {...}); .Ve .PP Send message or frame non-blocking via WebSocket, the optional drain callback will be invoked once all data has been written. .PP .Vb 2 \& # Send "Ping" frame \& $ws\->send([1, 0, 0, 0, 9, \*(AqHello World!\*(Aq]); .Ve .ie n .SS """server_handshake""" .el .SS "\f(CWserver_handshake\fP" .IX Subsection "server_handshake" .Vb 1 \& $ws\->server_handshake; .Ve .PP WebSocket handshake. .ie n .SS """server_read""" .el .SS "\f(CWserver_read\fP" .IX Subsection "server_read" .Vb 1 \& $ws\->server_read($data); .Ve .PP Read raw WebSocket data. .ie n .SS """server_write""" .el .SS "\f(CWserver_write\fP" .IX Subsection "server_write" .Vb 1 \& my $chunk = $ws\->server_write; .Ve .PP Raw WebSocket data to write. .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, .