I'm looking at building  a mojo app that has a websocket *client* on a 
timer that checks our nodejs app, and serves the results of those checks 
via a url. But I'm having trouble getting the websocket client to work 
inside a mojolicious app.

This script, when run as "perl mojo-test-short.pl eval", connects to the 
nodejs server and says that $tx is what I expect "tx is 
*Mojo::Transaction::WebSocket*=HASH(0x34c32d0)", so this is (I believe) the 
behavior I want

-------------------------

use Mojolicious::Lite;

my $ua = Mojo::UserAgent->new;
$ua->websocket('ws://10.200.2.81:9083/socket.io/1/websocket/' => sub {
      my $tx = pop;
      say "tx is $tx";
});

Mojo::IOLoop->start;

---------------

But this approach inside a running mojolicious app says that $tx is a 
*Mojo::Transaction::HTTP*, it never connects to the nodejs server (never 
sends anything over the wire at all) and of course dies because that 
package doesn't have an "on_finish" method

 (in cleanup) Can't locate object method "on_finish" via package 
"Mojo::Transaction::HTTP"

-----------------
sub startup {
    ...snip...
    Mojo::IOLoop->recurring(3 => \&read_datastream);
}
sub read_datastream {
    my $ua = Mojo::UserAgent->new;
    $ua->websocket('ws://10.200.2.81:9083/socket.io/1/websocket/' => sub {
          my $tx = pop;
          say "tx is a $tx";
          $tx->on_finish( sub { say "finished tx?" });
    });
}
---------------------------

The pod for the websocket method in Mojo::UserAgent says 

The callback will receive either a Mojo::Transaction::WebSocket *or* 
Mojo::Transaction::HTTP 
object.


but I don't understand *why* it can send back either one, or what I'm 
supposed to do with a Mojo::Transaction::HTTP object if I get one.  The 
sample code in Mojo::UserAgent doesn't address that scenario at all.

Any suggestions would be hugely appreciated. Thanks!



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

Reply via email to