Webcams and Mojolicious Flushing?

I use the Mojolicious :: Lite module to start the websockets server to handle the protocol. This is the testing code that I am currently using for the client:

socket.onopen = function(){$.each(proxies, function(){socket.send(this);});} socket.onmessage = function(response){alert(response);} 

And server

 websocket '/' => sub { my $self = shift; $self->on(message => sub { my ($self, $message) = @_; my @info = split /-/,$message; $mech_proxy = WWW::Mechanize->new(timeout=>$info[1], autocheck=>0); $self->send(test_proxy($info[0]) => sub{sleep(int(rand(10)))}); }); }; app->start; 

In any case, I thought that this explicitly eliminates the need to reset the output, since initially I actually only performed one starting client side, and then I received a return message sent in a loop on the server side; this did not work because I could not turn off the output and had to wait for the loop to complete. However, changing it did not help, since I still need to wait until the last sending to the server is sent, and only then the data will be sent to the client. Do you have any ideas on how I can receive β€œupdates” during processing, i.e. Display server response as it is sent?

EDIT: I get mixed results with setTimout(socket.send(this),1000) . I realized that, probably, in order to dump data, new data should be sent only after the previous data has been processed and completely recorded on the server side. If this proves really correct, it should be possible to write to the client side so that it only sends new data after it has received results from previous data sent; this will provide the effect of obtaining the desired live updates.

Greetings

+4
source share
1 answer

OK sorted it, as mentioned above, new data should be sent only after receiving a response (code below). Also, one remark, surprisingly, actually happens faster than execution with the jquery loop.

 socket.onopen = function(){ socket.send(proxies[0]+'-'+timeout); proxies.splice(0,1); } socket.onmessage = function(response){ if (proxies.length > 0) { socket.send(proxies[0]+'-'+timeout); proxies.splice(0,1); } document.write(response.data); } 
+1
source

Source: https://habr.com/ru/post/1403244/


All Articles