Hi!

It seems to me that you should structure your code such that each command
emits a 'message' event; it appears that you have a single routine which
runs all of your commands and then emits a single message for all of the
output.  Impossible for me to say of course, but that's what I get out of
what I see from your snippet.

Alternatively, backend() needs to be non-blocking and there's a lot behind
the scenes there.

Sorry that's not any help, but I can at least reassure you that what you
are driving towards is definitely possible!  You can definitely send the
result back to the browser via websocket of just one command without
waiting for the others to finish.

This sounds like a project I'd be interested in contributing to if you can
make your code public.  I've worked on similar things in the past,
specifically for monitoring Linux boxes.

On Thu, Jan 17, 2019 at 11:30 PM Peter L <kutao.h...@gmail.com> wrote:

> Hi,
>
> I have a network equipment which is similar to the Cisco L3 switch. I use
> mojo to setup a web server on a Linux PC. The browser can send some CLI
> commands via websocket to web server. The web server can run these commands
> on network equipment and send all the results back to the browser via
> websocket. It works. But, It need to take some time to wait for all results
> done. In this case, if I have many CLI commands, it will take a long time
> to wait all results done. I want to send the result back to the browser if
> one command is executed without waiting for the other commands executing.
> Is there any way to do it via websocket?
>
>
>
> websocket "/runcmd" => sub {
>
>     $c->shift;
>
>     ...
>
>     $c->on(message => sub {
>          my ($c, @commands) = @_;
>
>          foreach ( @commands) {
>
>               # back-end to run commands via ssh/telnet session
>               my $ret = backend( $_);
>
>               $c->send( encode_json { result => $ret});
>          }
>
>     });
>
>     ...
> }
>
> Thanks,
> Peter
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to