in reply to Persistent connection to a websocket/gateway (wss://)
Mojolicious supports WebSocket. This example is copy-pasted from their documentation:
use Mojo::UserAgent; use Mojo::IOLoop; # Open WebSocket to echo service my $ua = Mojo::UserAgent->new; $ua->websocket('ws://echo.websocket.org' => sub { my ($ua, $tx) = @_; # Check if WebSocket handshake was successful say 'WebSocket handshake failed!' and return unless $tx->is_websocke +t; # Wait for WebSocket to be closed $tx->on(finish => sub { my ($tx, $code, $reason) = @_; say "WebSocket closed with status $code."; }); # Close WebSocket after receiving one message $tx->on(message => sub { my ($tx, $msg) = @_; say "WebSocket message: $msg"; $tx->finish; }); # Send a message to the server $tx->send('Hi!'); }); # Start event loop if necessary Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Persistent connection to a websocket/gateway (wss://)
by james28909 (Deacon) on May 16, 2017 at 17:52 UTC | |
|
Re^2: Persistent connection to a websocket/gateway (wss://)
by james28909 (Deacon) on May 19, 2017 at 20:56 UTC |