http://www.perlmonks.org?node_id=1081657


in reply to Re^2: PSGI, Plack, Twiggy, AnyEvent and SockJS... I need help
in thread PSGI, Plack, Twiggy, AnyEvent and SockJS... I need help

Please don't modify your original code that much, as people then can't learn from seeing your code progress through the stages.

The next step would be to add (much) more amounts of server-side logging. print or warn at every step of the process. At least add logging statements to the following points:

mount '/echo' => SockJS->new( handler => sub { warn "Creating new session"; my ($session) = @_; $session->on( 'data' => sub { my $session = shift; warn "got new data"; $session->write('got your message'); warn "Wrote response"; } ); $session->write('connected'); warn "Wrote greeting"; my $w_cond = AnyEvent->condvar; my $w; $w = AnyEvent->timer( after => 0, interval => 5, cb => sub { undef $w; # cleanup $session->write('5 seconds have passed'); warn "Wrote timer message"; $w_cond->send(); } ); $w_cond->recv; warn "Leaving"; }; );

Replies are listed 'Best First'.
Re^4: PSGI, Plack, Twiggy, AnyEvent and SockJS... I need help
by xtpu2 (Acolyte) on Apr 09, 2014 at 15:29 UTC

    Sorry! I will stop doing that. So far, one of the issues has been resolved: the problem with connection closing immediately. The node with updated code is here.

    There is still a problem with the timer firing only once.

      Of course the timer fires only once, because we undef the timer in its callback. If you want to keep the timer running, you need to move its variable to somewhere that stays alive or never undef it in the callback.