Re: [Mojolicious] Best alternative for client / server polling?

2020-05-18 Thread Felipe Gasper


> On May 18, 2020, at 7:45 PM, Miguel Manso  wrote:
> 
> Hi there,
> 
> Ive a Perl client that fetched some data every 3 seconds and post it to an 
> API. Both client and server are written using mojo. Client uses 
> Mojo::UserAgent to post JSON and server is a Mojolicious app being served 
> with hypnotoad.
> 
> I can have dozens of these clients which mean that each of them will be 
> posting data and receiving from the server every 3 secs. I can easily do this 
> using basic post calls but I wonder if there is a better way to achieve the 
> same? Something like keeping connections opened for a period of time while 
> sending and receiving data through the same connection?
> 
> Ive seen websockets info but it seems it’s allways oriented to the client 
> being in JavaScript.
> 
> Any thoughts on the subject?

We’ve had great success deploying WebSocket in lieu of TCP for server-to-server 
communication. You harness the routing that a web framework like Mojo does for 
you--so no futzing with firewalls and the like--but you still get the real-time 
communication that a raw TCP socket would give you. There’s a CLI utility 
called “websocat” that basically functions as “netcat for WebSocket”, if that’s 
of use to you.

An alternative technology, if you only need a server-to-client stream, is 
Server-Sent Events (SSE). It’s basically an open-ended HTTP response, with the 
client parsing each chunk of that response as it arrives. Most browsers support 
it via the EventStream object, and I suspect it’d be pretty straightforward to 
rig up a Mojo SSE client, too. It’s a bit simpler, too, since it follows HTTP 
semantics. Not as robust, though, as it lacks the close status mechanism that 
WebSocket provides. (The server basically has to wait until it sees 
EPIPE/SIGPIPE to know that the client has stopped listening.)

-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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/B7BB55F8-9810-440B-9F79-919A1B664D05%40felipegasper.com.


Re: [Mojolicious] Best alternative for client / server polling?

2020-05-18 Thread Dan Book
Mojo::UserAgent is a great websocket client. See
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#WebSockets, and for
the server
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#WebSocket-web-service
.

-Dan

On Mon, May 18, 2020 at 7:47 PM Miguel Manso  wrote:

> Hi there,
>
> Ive a Perl client that fetched some data every 3 seconds and post it to an
> API. Both client and server are written using mojo. Client uses
> Mojo::UserAgent to post JSON and server is a Mojolicious app being served
> with hypnotoad.
>
> I can have dozens of these clients which mean that each of them will be
> posting data and receiving from the server every 3 secs. I can easily do
> this using basic post calls but I wonder if there is a better way to
> achieve the same? Something like keeping connections opened for a period of
> time while sending and receiving data through the same connection?
>
> Ive seen websockets info but it seems it’s allways oriented to the client
> being in JavaScript.
>
> Any thoughts on the subject?
>
> Thanks in advance.
>
> --
> 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/127f7769-222c-4e76-80bf-af36df28a5e0%40googlegroups.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/CABMkAVU4OL2D6j8hmXpPwTif-5KW2WTDeeF2Enczmizod0Q6uQ%40mail.gmail.com.


[Mojolicious] Best alternative for client / server polling?

2020-05-18 Thread Miguel Manso
Hi there,

Ive a Perl client that fetched some data every 3 seconds and post it to an API. 
Both client and server are written using mojo. Client uses Mojo::UserAgent to 
post JSON and server is a Mojolicious app being served with hypnotoad.

I can have dozens of these clients which mean that each of them will be posting 
data and receiving from the server every 3 secs. I can easily do this using 
basic post calls but I wonder if there is a better way to achieve the same? 
Something like keeping connections opened for a period of time while sending 
and receiving data through the same connection?

Ive seen websockets info but it seems it’s allways oriented to the client being 
in JavaScript.

Any thoughts on the subject?

Thanks in advance.

-- 
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/127f7769-222c-4e76-80bf-af36df28a5e0%40googlegroups.com.