Websocket cat

25 views
Skip to first unread message

John

unread,
Dec 15, 2019, 11:38:37 AM12/15/19
to mojol...@googlegroups.com
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

sri

unread,
Dec 15, 2019, 11:57:10 AM12/15/19
to Mojolicious
That module doesn't actually exist anymore for quite some time. Use the guides to get started.


--
sebastian 

Felipe Gasper

unread,
Dec 15, 2019, 11:57:49 AM12/15/19
to mojol...@googlegroups.com
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
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/cc400d5f-e7e2-1595-70e5-94ff1974eb27%40tonebridge.com.

John

unread,
Dec 15, 2019, 1:11:35 PM12/15/19
to mojol...@googlegroups.com
Thanks for both your responses.  I will look at user agent.

Reply all
Reply to author
Forward
0 new messages