Net::Async::WebSocket::Protocol - send and receive WebSocket frames
Net::Async::WebSocket::Protocol
This subclass of IO::Async::Stream implements an established WebSocket connection, that has already completed its setup handshaking and is ready to pass frames.
Objects of this type would not normally be constructed directly. For WebSocket clients, see Net::Async::WebSocket::Client, which is a subclass of this. For WebSocket servers, see Net::Async::WebSocket::Server, which constructs objects in this class when it accepts a new connection and passes it to its event handler.
The following events are invoked, either using subclass methods or CODE references in parameters:
$self->on_text_frame( $text ) $on_text_frame->( $self, $text )
Invoked when a text frame is received. It is passed a Unicode character string formed by decoding the received UTF-8 bytes.
$self->on_frame( $text ) $on_frame->( $self, $text )
A synonym for on_text_frame, provided for backward compatibility.
on_text_frame
This may be removed in a later version.
$self->on_..._frame( $bytes ) $on_..._frame->( $self, $bytes )
Invoked when other types of frame are received. These will be passed plain byte strings.
$self->on_raw_frame( $frame, $bytes ) $on_raw_frame->( $self, $frame, $bytes )
Invoked when a frame is received that does not have a specific handler defined of one of the above types. $frame will be an instance of Protocol::WebSocket::Frame.
$frame
The following named parameters may be passed to new or configure:
new
configure
CODE references for event handlers.
Whether frames constructed and sent by this instance will be masked.
The following methods documented with a trailing call to ->get return Future instances.
->get
$self->send_frame( @args )->get
Sends a frame to the peer containing containing the given string. The arguments are passed to Protocol::WebSocket::Frame's new method.
This method is discouraged in favour of the more specific ones listed below, and is only provided for back-compatibility or for sending new frame types not recognised by the specific methods.
$self->send_text_frame( $text, %params )->get
Sends a text frame to the peer. The given string will be treated as a Unicode character string, and sent as UTF-8 encoded bytes.
Any additional arguments will be passed as parameters to the underlying "write" in IO::Async::Stream call.
$self->send_binary_frame( $bytes, %params )->get $self->send_ping_frame( $bytes, %params )->get $self->send_pong_frame( $bytes, %params )->get $self->send_close_frame( $bytes, %params )->get
Sends a frame of the given type to the peer.
Paul Evans <leonerd@leonerd.org.uk>
To install Net::Async::WebSocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::WebSocket
CPAN shell
perl -MCPAN -e shell install Net::Async::WebSocket
For more information on module installation, please visit the detailed CPAN module installation guide.