AnyEvent-WebSocket-Client
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
$client->connect("ws://localhost:1234/service")->cb(sub {
# make $connection an our variable rather than
# my so that it will stick around. Once the
# connection falls out of scope any callbacks
# tied to it will be destroyed.
our $connection = eval { shift->recv };
if($@) {
# handle error...
warn $@;
return;
}
# 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 the connection (either inside or
# outside another callback)
$connection->close;
});
## uncomment to enter the event loop before exiting.
## Note that calling recv on a condition variable before
## it has been triggered does not work on all event loops
#AnyEvent->condvar->recv;
DESCRIPTION
This class provides an interface to interact with a web server that
provides services via the WebSocket protocol in an AnyEvent context. It
uses Protocol::WebSocket rather than reinventing the wheel. You could
use AnyEvent and Protocol::WebSocket directly if you wanted finer grain
control, but if that is not necessary then this class may save you some
time.
The recommended API was added to the AnyEvent::WebSocket::Connection
class with version 0.12, so it is recommended that you include that
version when using this module. The older version of the API has since
been deprecated and removed.
ATTRIBUTES
timeout
Timeout for the initial connection to the web server. The default is
30.
ssl_no_verify
If set to true, then secure WebSockets (those that use SSL/TLS) will
not be verified. The default is false.
ssl_ca_file
Provide your own CA certificates file instead of using the system
default for SSL/TLS verification.
protocol_version
The protocol version. See Protocol::WebSocket for the list of supported
WebSocket protocol versions.
subprotocol
List of subprotocols to request from the server. This class will throw
an exception if none of the protocols are supported by the server.
http_headers
Extra headers to include in the initial request. May be either
specified as a hash reference, or an array reference. For example:
AnyEvent::WebSocket::Client->new(
http_headers => {
'X-Foo' => 'bar',
'X-Baz' => [ 'abc', 'def' ],
},
);
AnyEvent::WebSocket::Client->new(
http_headers => [
'X-Foo' => 'bar',
'X-Baz' => 'abc',
'X-Baz' => 'def',
],
);
Will generate:
X-Foo: bar
X-Baz: abc
X-Baz: def
Although, the order cannot be guaranteed when using the hash style.
max_payload_size
The maximum payload size for received frames. Currently defaults to
whatever Protocol::WebSocket defaults to.
max_fragments
The maximum number of fragments for received frames. Currently defaults
to whatever Protocol::WebSocket defaults to.
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.528 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )