Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: mojo::websocket reconnect

by alexander_lunev (Pilgrim)
on May 19, 2022 at 20:43 UTC ( [id://11144017]=note: print w/replies, xml ) Need Help??


in reply to mojo::websocket reconnect

Hello! Try this:
use 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;
Maybe this answer will tell you more: https://stackoverflow.com/a/70136684

Replies are listed 'Best First'.
Re^2: mojo::websocket reconnect
by james28909 (Deacon) on May 23, 2022 at 07:15 UTC

    I just wanted to tell you that this actually helped me with another problem i was going to face. I was going to need to open a completely new websocket to a different endpoint, but doing it like you described above sure did make that a very simple task. Thanks again!!!

      You're welcome!
Re^2: mojo::websocket reconnect
by james28909 (Deacon) on May 20, 2022 at 18:11 UTC
    Excellent! This worked great. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11144017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-18 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found