in reply to mojo::websocket reconnect
Maybe this answer will tell you more: https://stackoverflow.com/a/70136684use strict; use Mojo::UserAgent; my $ua = Mojo::UserAgent->new; my $url = "ws://some.url/path"; my $globals; my $connect_ws; $connect_ws = sub { my ($ua, $tx) = @_; $tx->on(json => sub { my ($tx, $json) = @_; # populate $globals here and listen for $opcode = 7 # if ($opcode eq 7) { $tx->finish(); } }); $tx->on(finish => sub { my ($ws, $code, $reason) = @_; print "WebSocket closed with status $code. $reason\n"; $ua->websocket($url => $connect_ws); }); # if we have some globals, then we're resuming - send tokens etc if ($globals) { $tx->send({ json => $globals }) } }; $ua->websocket($url => $connect_ws); Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: mojo::websocket reconnect
by james28909 (Deacon) on May 23, 2022 at 07:15 UTC | |
by alexander_lunev (Pilgrim) on May 24, 2022 at 05:19 UTC | |
|
Re^2: mojo::websocket reconnect
by james28909 (Deacon) on May 20, 2022 at 18:11 UTC |