Skip to content

Instantly share code, notes, and snippets.

@bduggan
Created August 2, 2011 14:04
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 bduggan/1120245 to your computer and use it in GitHub Desktop.
Save bduggan/1120245 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Mojo::UserAgent;
use strict;
use warnings;
use 5.10.0;
my $ua = Mojo::UserAgent->new();
my $destination = 'ws://localhost:9999/down';
$ua->log->debug("Starting $$");
my $connect;
my $tx;
$connect = sub {
my $c = shift;
$tx = pop;
if ( my $e = $tx->error ) {
$ua->log->debug("error (retry in 5 seconds): $e");
Mojo::IOLoop->singleton->timer(
5 => sub { $ua->websocket( $destination => $connect ); } );
return;
}
$ua->log->debug("connected to $destination");
};
$ua->websocket($destination => $connect);
Mojo::IOLoop->singleton->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment