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
    I was able to get the response back using this code! I am so greatful because I would have never figured this much out. Now that i have a good starting point, I can see how it works. Now I think I just need to setup a timed interval to send back data, then the rest is down hill (hopefully, i may be back though haha!).
Re^2: Persistent connection to a websocket/gateway (wss://)
by james28909 (Deacon) on May 19, 2017 at 20:56 UTC
    I was more than able to get it to work. It did, however, take me a few days of learning http responses and headers a little bit, but I completed my goal, and am now building mucho functionality into the script.