SHOW:
|
|
- or go back to the newest paste.
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(); |