Skip to content

Instantly share code, notes, and snippets.

@linagee
Created April 2, 2015 02:27
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 linagee/e9cb743dcd97a5762e03 to your computer and use it in GitHub Desktop.
Save linagee/e9cb743dcd97a5762e03 to your computer and use it in GitHub Desktop.
my $websocket_URL = 'myURLhere';
sub websocket_loop {
my ($ua, $tx) = @_;
say 'WebSocket handshake failed!' and return unless $tx->is_websocket;
$tx->on(finish => sub {
print "websocket killed!!! trying reconnect...\n";
$ua->websocket($websocket_URL => \&websocket_loop);
});
print "Computer Connected!\n";
$tx->send({json => {msg => 'Computer Connected!'}});
Mojo::IOLoop->recurring(0 => sub {
$tx->send({json => {msg => 'cool things get sent here'}});
}
});
}
$ua->websocket($websocket_URL => \&websocket_loop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment