I’ve spent very little time with Mojo as a WS client, but I found the example in Mojo::UserAgent’s documentation to be enough to get me where I needed to go.
===== $ua->websocket('ws+unix://%2Ftmp%2Fmyapp.sock/echo.json' => sub { my ($ua, $tx) = @_; say 'WebSocket handshake failed!' and return unless $tx->is_websocket; $tx->on(json => sub { my ($tx, $hash) = @_; say "WebSocket message via JSON: $hash->{msg}"; $tx->finish; }); $tx->send({json => {msg => 'Hello World!'}}); }); Mojo::IOLoop->start unless Mojo::IOLoop->is_running; ===== ^^ So, specify remote server and port in the wss:// URL. -FG > On Dec 15, 2019, at 11:38 AM, John <j...@tonebridge.com> wrote: > > I am trying to get my head around using mojolicious as a websocket client. I > have used it as a websocket server in various projects. To start I wanted > to create a simple command line utility that connected to a websocket server > and printed the json it received. > > I began with the documentation: > > https://mojolicious.org/perldoc/Mojo/IOLoop/Stream/WebSocketClient > > Due to my lack of understanding the basics a couple things confuse me. > Where do I specify the remote server/port and how do I define $handle? My > code is pretty much the example at that location but with "use > warnings/strict" added. I haven't been able to get an understanding based > on my review of the docs. > > It would be great to see an example as I expect others have done this before. > Otherwise some pointers wold be appreciated. > > Thanks, > > John > > -- > You received this message because you are subscribed to the Google Groups > "Mojolicious" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to mojolicious+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/mojolicious/cc400d5f-e7e2-1595-70e5-94ff1974eb27%40tonebridge.com. -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/052B04A6-DAB2-4412-9F1A-4C935D1CD263%40felipegasper.com.