AnyEvent::WebSocket::Connection - WebSocket connection for AnyEvent
version 0.22
# send a message through the websocket... $connection->send('a message'); # recieve message from the websocket... $connection->on(each_message => sub { # $connection is the same connection object # $message isa AnyEvent::WebSocket::Message my($connection, $message) = @_; ... }); # handle a closed connection... $connection->on(finish => sub { # $connection is the same connection object my($connection) = @_; ... }); # close an opened connection # (can do this either inside or outside of # a callback) $connection->close;
(See AnyEvent::WebSocket::Client or AnyEvent::WebSocket::Server on how to create a connection)
This class represents a WebSocket connection with a remote server or a client.
If the connection object falls out of scope then the connection will be closed gracefully.
This class was created for a client to connect to a server via AnyEvent::WebSocket::Client, and was later extended to work on the server side via AnyEvent::WebSocket::Server. Once a WebSocket connection is established, the API for both client and server is identical.
The underlying AnyEvent::Handle object used for the connection. WebSocket handshake MUST be already completed using this handle. You should not use the handle directly after creating AnyEvent::WebSocket::Connection object.
Usually only useful for creating server connections, see below.
If set to true, it masks outgoing frames. The default is false.
Send a message to the other side. $message may either be a string (in which case a text message will be sent), or an instance of AnyEvent::WebSocket::Message.
$message
Register a callback to a particular event.
For each event $connection is the AnyEvent::WebSocket::Connection and and $message is an AnyEvent::WebSocket::Message (if available).
$connection
$cb->($connection, $message)
Called each time a message is received from the WebSocket.
Called only for the next message received from the WebSocket.
$cb->($connection)
Called when the connection is terminated
Close the connection.
Although written originally to work with AnyEvent::WebSocket::Client, this class was designed to be used for either client or server WebSocket connections. For details, contact the author and/or take a look at the source for AnyEvent::WebSocket::Client and the examples that come with Protocol::WebSocket.
The methods in this section are deprecated and may be removed from a future version of this class. They should not be used for new code, and are only remain documented here to aid in understanding legacy code that use them.
Register a callback to be called on each subsequent message received. The message itself will be passed in as the only parameter to the callback. The message is a decoded text string.
Register a callback to be called the next message received. The message itself will be passed in as the only parameter to the callback. The message is a decoded text string.
Register a callback to be called when the connection is closed.
AnyEvent::WebSocket::Client
AnyEvent::WebSocket::Message
AnyEvent::WebSocket::Server
AnyEvent
RFC 6455 The WebSocket Protocol
author: Graham Ollis <plicease@cpan.org>
contributors:
Toshio Ito
This software is copyright (c) 2013 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install AnyEvent::WebSocket::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::WebSocket::Client
CPAN shell
perl -MCPAN -e shell install AnyEvent::WebSocket::Client
For more information on module installation, please visit the detailed CPAN module installation guide.