Skip to content

Instantly share code, notes, and snippets.

@pabelanger
Created October 17, 2013 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pabelanger/7028799 to your computer and use it in GitHub Desktop.
Save pabelanger/7028799 to your computer and use it in GitHub Desktop.
use Mojo::UserAgent;
use warnings;
use strict;
use 5.14.0;
my $ua = Mojo::UserAgent->new;
$ua->websocket('ws://username:password@localhost:8088/ari/events?app=demo' => sub {
my ($ua, $tx) = @_;
say "WebSocket handshake failed!" and return unless $tx->is_websocket;
$tx->on(finish => sub {
my ($tx, $code, $reason) = @_;
say "WebSocket closed with status $code.";
});
$tx->on(message => sub {
my ($tx, $msg) = @_;
say "WebSocket message: $msg";
$tx->finish;
});
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment