Created
October 17, 2013 17:18
-
-
Save pabelanger/7028799 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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