AnyEvent-WebSocket-Client
view release on metacpan or search on metacpan
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.
env_proxy
If you set true to this boolean attribute, it loads proxy settings from
environment variables. If it finds valid proxy settings, connect method
will use that proxy.
Default: false.
For ws WebSocket end-points, first it reads ws_proxy (or WS_PROXY)
environment variable. If it is not set or empty string, then it reads
http_proxy (or HTTP_PROXY). For wss WebSocket end-points, it reads
wss_proxy (WSS_PROXY) and https_proxy (HTTPS_PROXY) environment
variables.
METHODS
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
URI::ws, 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 AnyEvent::Socket's tcp_connect function, so please note
that function's idiosyncrasies in the AnyEvent::Socket documentation.
In particular, you can pass in unix/ as the host and a filesystem path
as the "port" to connect to a unix domain socket.
This method will return an AnyEvent condition variable which you can
attach a callback to. The value sent through the condition variable
will be either an instance of AnyEvent::WebSocket::Connection or a
croak message indicating a failure. The synopsis above shows how to
catch such errors using eval.
FAQ
My program exits before doing anything, what is up with that?
See this FAQ from AnyEvent:
AnyEvent::FAQ#My-program-exits-before-doing-anything-whats-going-on.
It is probably also a good idea to review the AnyEvent documentation if
you are new to AnyEvent or event-based programming.
My callbacks aren't being called!
Make sure that the connection object is still in scope. This often
happens if you use a my $connection variable and don't save it
somewhere. For example:
$client->connect("ws://foo/service")->cb(sub {
my $connection = eval { shift->recv };
( run in 0.935 second using v1.01-cache-2.11-cpan-df04353d9ac )