Mojo::UserAgent websocket not working

166 views
Skip to first unread message

Lloyd Fournier

unread,
Jun 15, 2013, 4:38:44 AM6/15/13
to mojol...@googlegroups.com
Hi Guys,
I tried the http://mojolicio.us/perldoc/Mojolicious/Lite#WebSockets example echo server. That worked fine, but when I try to do the echo from Mojo::UserAgent using the example here: http://mojolicio.us/perldoc/Mojo/UserAgent#websocket it doesn't work. Looking at tcpdump it doesn't even look like it tries to establish a connection (there is nothing).

 All I get is "Premature connection close" (pretty much instantly).

websockets.org has a test echo thing here: http://www.websocket.org/echo.html

But trying to connect to it with ua doesn't work for me. I get the same thing. I've tried it on multiple environments and different versions of perl. Mojolicious is at 4.14. So can people run the below code and have it work?

use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
$ua->websocket('ws://echo.websocket.org' =>
               sub {
                   my ($ua, $tx) = @_;
                   if ( $tx->is_websocket){
                       print "win\n";
                   }else {
                       print "lose: ".$tx->error."\n";
                   }
                   return;
               });

Thanks in advance.

LL


sri

unread,
Jun 15, 2013, 2:17:38 PM6/15/13
to Mojolicious
>  All I get is "Premature connection close" (pretty much instantly).

Your Mojo::UserAgent instance goes out of scope.

--
sebastian

Lloyd Fournier

unread,
Jun 16, 2013, 8:33:29 AM6/16/13
to mojol...@googlegroups.com, kra...@googlemail.com
Adding
Mojo::IOLoop->start;
to the end of it fixed it. Thanks.

I can get a basic echo Mojolicious websocket server and talk to it with the agent now....but for some reason the 'ws://echo.websocket.org' server never echos my call even though it works with a mojolicious lite server. The connection does upgrade to websocket successfully though. I'm guessing it's their the server's fault. It works fine in JS from firefox, but it is discriminating against the mojo user agent somehow.

Cheers,
LL
Reply all
Reply to author
Forward
0 new messages