After I started the client with the eserver websocket server, it will disconnect after about half a minute with the message WebSocket closed with status 1006 .
Please suggest how to avoid this behavior (browsers do not seem to be affected)
use 5.20.0; use Mojo::UserAgent; use Mojo::IOLoop; sub ws_connect { state $ua; say "Connecting.."; $ua = Mojo::UserAgent->new; $ua->websocket('ws://127.0.0.1:3000/echo' => \&onConnect); } sub onConnect { my ($ua, $tx) = @_; if (!$tx->is_websocket) { say 'WebSocket handshake failed!'; } say "Connected!"; $tx->on(finish => sub { my ($tx, $code) = @_; say "WebSocket closed with status $code"; }); } ws_connect(); Mojo::IOLoop->start;
echo server
use Mojolicious::Lite; use Mojo::EventEmitter; helper events => sub { state $events = Mojo::EventEmitter->new };
Dry27 source share