AnyEvent-WebSocket-Client
view release on metacpan or search on metacpan
lib/AnyEvent/WebSocket/Client.pm view on Meta::CPAN
'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.
=head2 max_payload_size
The maximum payload size for received frames. Currently defaults to whatever
L<Protocol::WebSocket> defaults to.
=head2 max_fragments
The maximum number of fragments for received frames. Currently defaults to whatever
L<Protocol::WebSocket> defaults to.
=head2 env_proxy
If you set true to this boolean attribute, it loads proxy settings
from environment variables. If it finds valid proxy settings,
C<connect> method will use that proxy.
Default: false.
For C<ws> WebSocket end-points, first it reads C<ws_proxy> (or
C<WS_PROXY>) environment variable. If it is not set or empty string,
then it reads C<http_proxy> (or C<HTTP_PROXY>). For C<wss> WebSocket
end-points, it reads C<wss_proxy> (C<WSS_PROXY>) and C<https_proxy>
(C<HTTPS_PROXY>) environment variables.
=head1 METHODS
=head2 connect
my $cv = $client->connect($uri)
my $cv = $client->connect($uri, $host, $port);
Open a connection to the web server and open a WebSocket to the resource
defined by the given URL. The URL may be either an instance of L<URI::ws>,
L<URI::wss>, or a string that represents a legal WebSocket URL.
You can override the connection host and port by passing them in as the
second and third argument. These values (if provided) are passed directly
into L<AnyEvent::Socket>'s C<tcp_connect> function, so please note that
function's idiosyncrasies in the L<AnyEvent::Socket> documentation. In
particular, you can pass in C<unix/> as the host and a filesystem path
as the "port" to connect to a unix domain socket.
This method will return an L<AnyEvent> condition variable which you can
attach a callback to. The value sent through the condition variable will
be either an instance of L<AnyEvent::WebSocket::Connection> or a croak
message indicating a failure. The synopsis above shows how to catch
such errors using C<eval>.
=head1 FAQ
=head2 My program exits before doing anything, what is up with that?
See this FAQ from L<AnyEvent>:
L<AnyEvent::FAQ#My-program-exits-before-doing-anything-whats-going-on>.
It is probably also a good idea to review the L<AnyEvent> documentation
if you are new to L<AnyEvent> or event-based programming.
=head2 My callbacks aren't being called!
Make sure that the connection object is still in scope. This often happens
if you use a C<my $connection> variable and don't save it somewhere. For
example:
$client->connect("ws://foo/service")->cb(sub {
my $connection = eval { shift->recv };
if($@)
{
warn $@;
return;
}
...
});
Unless C<$connection> is saved somewhere it will get deallocated along with
any associated message callbacks will also get deallocated once the connect
callback is executed. One way to make sure that the connection doesn't
get deallocated is to make it a C<our> variable (as in the synopsis above)
instead.
=head1 CAVEATS
This is pretty simple minded and there are probably WebSocket features
that you might like to use that aren't supported by this distribution.
Patches are encouraged to improve it.
=head1 SEE ALSO
=over 4
=item *
L<AnyEvent::WebSocket::Connection>
=item *
L<AnyEvent::WebSocket::Message>
( run in 0.500 second using v1.01-cache-2.11-cpan-39bf76dae61 )