Advertisement
Guest User

Untitled

a guest
Dec 5th, 2012
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub connect_websock {
  2.     $ua->websocket('ws://localhost:3000/path' => sub {
  3.         my ($ua, $tx) = @_;
  4.         if (my $err = $tx->error) {
  5.             say "Error: $err";
  6.             Mojo::IOLoop->timer(5 => \&connect_websock);
  7.             return
  8.         }
  9.         $tx->on(message => sub {
  10.             my ($tx, $msg) = @_;
  11.             say $msg;
  12.         });
  13.  
  14.         $tx->on(finish => sub {
  15.             Mojo::IOLoop->timer(5 => \&connect_websock);
  16.         }
  17.     });
  18. }
  19.  
  20. connect_websock();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement