Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi everybody, I started looking into websocket as a way to push data from server to browser. I found example for Mojolicious written by Joel Berger. I am trying to make it to work, but no luck so far. here is the code:

websocket.pl

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 '/jquery-1.9.1.min.js' %= javascript '/jquery.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

While starting the script with morbo websocket.pl commands everything seems to be fine, but when I connect from the browser to the server I am getting following messages:

debug Your secret passphrase needs to be changed

debug GET "/"

debug Rendering template "index.html.ep" from DATA section

debug Template "layouts/basic.html.ep" not found

debug 200 OK (0.043215s, 23.140/s)

debug GET "/jquery-1.9.1.min.js"

debug Template "not_found.development.html.ep" not found

debug Template "not_found.html.ep" not found

debug Rendering inline template "fd403ab55a4c875e35b42428816134c7"

debug Rendering inline template "dd85456cf9f44e1e43bebae130a7f9df"

debug 404 Not Found (0.201262s, 4.969/s)

debug GET "/jquery.flot.js"

debug Template "not_found.development.html.ep" not found

debug Template "not_found.html.ep" not found

debug Rendering cached inline template "fd403ab55a4c875e35b42428816134c7"

debug Rendering cached inline template "dd85456cf9f44e1e43bebae130a7f9df"

debug 404 Not Found (0.051227s, 19.521/s)

Any idea what's wrong?

Thanks like always

Robert


In reply to 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-03-29 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found