Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: real-time output from Mojolicious WebSockets?

by Anonymous Monk
on Dec 20, 2014 at 04:31 UTC ( [id://1110903]=note: print w/replies, xml ) Need Help??


in reply to Re^4: real-time output from Mojolicious WebSockets?
in thread real-time output from Mojolicious WebSockets?

oh right, the output is
Connection open. 12/19/2014, 8:30:17 PM : Entering log4. 12/19/2014, 8:30:17 PM : Leaving log4. **pause here** 12/19/2014, 8:30:19 PM : Entering myapp. 12/19/2014, 8:30:19 PM : 0...Fri Dec 19 20:30:19 2014 12/19/2014, 8:30:19 PM : 1...Fri Dec 19 20:30:19 2014 12/19/2014, 8:30:19 PM : 2...Fri Dec 19 20:30:19 2014 12/19/2014, 8:30:19 PM : 3...Fri Dec 19 20:30:19 2014 12/19/2014, 8:30:19 PM : Leaving myapp. 12/19/2014, 8:30:19 PM : after 3 0...Fri Dec 19 20:30:19 2014 **pause here** 12/19/2014, 8:30:22 PM : after 3 1...Fri Dec 19 20:30:22 2014 **pause here** 12/19/2014, 8:30:25 PM : after 3 2...Fri Dec 19 20:30:25 2014 **pause here** 12/19/2014, 8:30:28 PM : after 3 3...Fri Dec 19 20:30:28 2014
naturally it pauses at **pause here**

proc background if you're doing something which you can't fanagle into cooperative multitasking

Replies are listed 'Best First'.
Re^6: real-time output from Mojolicious WebSockets?
by icefishyu (Initiate) on Jan 11, 2016 at 09:25 UTC
    actually i have same question,
    There is long-time operation on server and I want update its progress on client-side.
    In several points on server-side code I call $web_socket->send(...) and process it on client-side ws.onmessage = function (event) {...};
    Server-side logic as below:
    some_computation1();
    $web_socket->send('computation1 end');
    ...
    some_computation15();
    $web_socket->send('computation15 end');
    ...
    some_computation100();
    $web_socket->send('computation100 end. All ok!');
    Client-side as below
    ws = new WebSocket(url);
    ws.onmessage = function (event) {
    $('#log_view').append('

    ' + event.data + '

    ');
    };
    ws.onopen = function (event) {
    ...
    };
    ws.onclose = function (event) {
    ...
    };
    Everything work fine, but not in realtime: all messages has received by client at one big bulk list and only after whole server-side script has finished.
    in fact, i need every message show up after one step finished.
    appreciate if any friends can help me.

      Have you made sure that there is no buffering going on between your script and the client? Maybe the websocket channel has gzip compression enabled which buffers?

      Have you written your progress output to a logfile in parallel to verify that your script arrives at the respective steps when you think it should?

      Your problem seems to be relatively common, but the only one with enough source code to maybe reproduce it (and a solution) was at Mojolicious websocket with server-side repeating events. So maybe you can either try that solution or work your code into something that we can run to try and reproduce your problem.

      Relevant keywords seem to be perl mojo websocket flush, but without seeing more of your code, it's hard to judge whether the solutions (or not) suggested fit your situation.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1110903]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found