[Mojolicious] Re: Using IO::Loop on websocket connection

2016-05-04 Thread Matija Papec

On Wednesday, May 4, 2016 at 1:09:50 PM UTC+2, Heiko Jansen wrote:
>
> Am Montag, 2. Mai 2016 17:20:47 UTC+2 schrieb Matija Papec:
>>
>>
>> I want to read from redis in non-blocking way and delay() looks like 
>> first choice for this kind of task (event callbacks are closures to session 
>> related variables).
>>
>
> Using delay() for non-blocking handling of requests (or more specifically 
> websocket messages) is fine;
> the question was why you try to define the event handlers inside some 
> delay step.
> I´d suggest re-reading the relevant docs (
> http://mojolicious.org/perldoc/Mojolicious/Guides/Tutorial#WebSockets 
> 
>  
> and 
> http://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#WebSocket-web-service
> ).
>
>
Ok, but I didn't notice explicit advice to avoid Delay when establishing ws 
connection.
Furthermore it poses problem only for desktop and mobile Chrome 
(IE11/Edge/mobile WP/FF were working fine).

And on top of that, everything behaves correct even for Chrome when in such 
case blocking Redis2 api is used.


regards

-- 
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.


[Mojolicious] Re: Using IO::Loop on websocket connection

2016-05-04 Thread Heiko Jansen
Am Montag, 2. Mai 2016 17:20:47 UTC+2 schrieb Matija Papec:
>
>
> I want to read from redis in non-blocking way and delay() looks like first 
> choice for this kind of task (event callbacks are closures to session 
> related variables).
>

Using delay() for non-blocking handling of requests (or more specifically 
websocket messages) is fine;
the question was why you try to define the event handlers inside some delay 
step.
I´d suggest re-reading the relevant docs 
(http://mojolicious.org/perldoc/Mojolicious/Guides/Tutorial#WebSockets and 
http://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#WebSocket-web-service).

Haven´t use websockets myself, yet, but something like this should be ok 
(untested!):

websocket '/ws/:sessid' => sub {
my ($c) = @_;
my $sessid = $c->stash('sessid');
$c->on(finish => sub { warn "disconnect\n" });
$c->on(json => sub {
my ($c, $msg) = @_;
warn "incoming ws json for session $sessid\n";
$c->delay(
sub { my $delay = shift; ... read from redis, pass it to delay 
... },
sub { my ( $delay, $data_from_redis ) = @_; ... do something 
with data ... },
);
   });
};

If that´s nonsense, somebody please correct me...

-- 
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.


[Mojolicious] Re: Using IO::Loop on websocket connection

2016-05-02 Thread Matija Papec

I want to read from redis in non-blocking way and delay() looks like first 
choice for this kind of task (event callbacks are closures to session 
related variables).

Alternatively I'll have to postpone redis access, and avoid delay() when 
establishing websocket connection.


regards



On Monday, May 2, 2016 at 3:13:49 PM UTC+2, Jan Henning Thorsen wrote:
>
> I don't get why you put that code inside delay().
>
> I would suggest moving it out of delay and right into the websocket sub.
>
> What are you trying to accomplish by putting it inside delay()?
>
>
> On Friday, April 29, 2016 at 3:20:29 PM UTC+2, Matija Papec wrote:
>>
>>
>> When I set websocket events inside $c->delay() browser disconnects 
>> almost immediately ("finish" event is properly triggered).
>> Please explain what is wrong here.
>>
>> ==
>> use Mojolicious::Lite;
>>
>> websocket '/ws/:sessid' => sub {
>> my ($c) = @_;
>>
>> $c->delay(sub{
>> $c->on(finish => sub { warn "disconnect\n" });
>> $c->on(json => sub { warn "incoming ws json \n" });
>> });
>> };
>>
>>
>>

-- 
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.


[Mojolicious] Re: Using IO::Loop on websocket connection

2016-05-02 Thread Jan Henning Thorsen
I don't get why you put that code inside delay().

I would suggest moving it out of delay and right into the websocket sub.

What are you trying to accomplish by putting it inside delay()?


On Friday, April 29, 2016 at 3:20:29 PM UTC+2, Matija Papec wrote:
>
>
> When I set websocket events inside $c->delay() browser disconnects almost 
> immediately ("finish" event is properly triggered).
> Please explain what is wrong here.
>
> ==
> use Mojolicious::Lite;
>
> websocket '/ws/:sessid' => sub {
> my ($c) = @_;
>
> $c->delay(sub{
> $c->on(finish => sub { warn "disconnect\n" });
> $c->on(json => sub { warn "incoming ws json \n" });
> });
> };
>
>
>

-- 
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.


[Mojolicious] Re: Using IO::Loop on websocket connection

2016-05-02 Thread Matija Papec

After some investigation it seems this issue manifests itself only with 
Chrome based browsers.
(mojo is v6.60)

My assumption is that server sends slightly different handshake messages 
when using $c->delay, and this has some profound impact on Chrome.
Browser complains with:
  WebSocket connection to 'ws://192.168.1.10:3000/ws/new' failed: One or 
more reserved bits are on: reserved1 = 1, reserved2 = 0, reserved3 = 0


Here are tcpdumps for both cases, where underscored packet seems to be 
missing in the second dump?

https://gist.github.com/mpapec/ea4b0885c3d982a1610c306976bb1dfc




On Friday, April 29, 2016 at 3:20:29 PM UTC+2, Matija Papec wrote:
>
>
> When I set websocket events inside $c->delay() browser disconnects almost 
> immediately ("finish" event is properly triggered).
> Please explain what is wrong here.
>
> ==
> use Mojolicious::Lite;
>
> websocket '/ws/:sessid' => sub {
> my ($c) = @_;
>
> $c->delay(sub{
> $c->on(finish => sub { warn "disconnect\n" });
> $c->on(json => sub { warn "incoming ws json \n" });
> });
> };
>
>
>

-- 
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.