Do you actually have those javascripts installed? It seems to work with the CDN versions
#!/usr/bin/env perl use Mojolicious::Lite; any '/' => 'index'; websocket '/data' => sub { my $self = shift; my $timer = Mojo::IOLoop->recurring( 1 => sub { state $i = 0; $self->send({ json => gen_data($i++) }); }); $self->on( finish => sub { Mojo::IOLoop->remove($timer); }); }; sub gen_data { my $x = shift; return [ $x, sin( $x + 2*rand() - 2*rand() ) ] } app->start; __DATA__ @@ index.html.ep % layout 'basic'; %= javascript 'https://code.jquery.com/jquery-2.1.4.min.js'; %= javascript 'https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquer +y.flot.js' <div id="plot" style="width:600px;height:300px"> </div> %= javascript begin var data = []; var plot = $.plot($('#plot'), [ data ]); var url = '<%= url_for('data')->to_abs %>'; var ws = new WebSocket( url ); ws.onmessage = function(e){ var point = JSON.parse(e.data); data.push(point); plot.setData([data]); plot.setupGrid(); plot.draw(); }; % end
Shell:
:~$ morbo t1.pl Server available at http://127.0.0.1:3000 [Wed Jun 17 21:54:11 2015] [debug] Your secret passphrase needs to be +changed [Wed Jun 17 21:54:11 2015] [debug] GET "/" [Wed Jun 17 21:54:11 2015] [debug] Rendering template "index.html.ep" +from DATA section [Wed Jun 17 21:54:11 2015] [debug] Template "layouts/basic.html.ep" no +t found [Wed Jun 17 21:54:11 2015] [debug] 200 OK (0.005384s, 185.736/s) [Wed Jun 17 21:54:11 2015] [debug] GET "/data" [Wed Jun 17 21:54:11 2015] [debug] Routing to a callback [Wed Jun 17 21:54:11 2015] [debug] 101 Switching Protocols (0.000710s, + 1408.451/s)
Browser shows oscillating lines and scaling horizontal axis. Where did you get this example from?

In reply to Re: Mojolicious Websocket example by trippledubs
in thread Mojolicious Websocket example by rkrasowski

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.