App-Pod
view release on metacpan or search on metacpan
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
say $tx->result->body;
})->catch(sub ($err) {
warn "Connection error: $err";
})->wait;
=head2 websocket
$ua->websocket('ws://example.com' => sub {...});
$ua->websocket('ws://example.com' => {DNT => 1} => ['v1.proto'] => sub {...});
Open a non-blocking WebSocket connection with transparent handshake, takes the same arguments as
L<Mojo::UserAgent::Transactor/"websocket">. The callback will receive either a L<Mojo::Transaction::WebSocket> or
L<Mojo::Transaction::HTTP> object, depending on if the handshake was successful.
$ua->websocket('wss://example.com/echo' => ['v1.proto'] => sub ($ua, $tx) {
say 'WebSocket handshake failed!' and return unless $tx->is_websocket;
say 'Subprotocol negotiation failed!' and return unless $tx->protocol;
$tx->on(finish => sub ($tx, $code, $reason) { say "WebSocket closed with status $code." });
$tx->on(message => sub ($tx, $msg) {
say "WebSocket message: $msg";
$tx->finish;
( run in 0.402 second using v1.01-cache-2.11-cpan-a1d94b6210f )