Quantcast
Channel: MarsHut
Viewing all articles
Browse latest Browse all 6551

Mojolicious unexpected websocket behavior

$
0
0
Two questions:

1) Does anyone know why the messages sent by 'wsinit' below should arrive
at the client in reverse order, i.e. 'msg 3' precedes 'msg 2' which
precedes 'msg 1' ?

2) Does anyone know why the first message to arrive (or more correctly, the
first message to be displayed by the browser), i.e. 'msg 3' doesn't arrive
until after a full 15 second delay?

Thanks.

# -- -
# server code (pointed to by route->websocket(controller => 'ctrl',
action => 'wsinit'), called from the javascript below):

sub wsinit

my $self = shift;

$self->send('msg 1');
sleep(5);
$self->send('msg 2');
sleep(5);
$self->send('msg 3');
sleep(5);

# -- -
# client code:

window.onload = function( )

window.x.ws.init( );
};
(function(namespace)

var _sock;
namespace.ws =

init: function( )

_sock = new WebSocket('ws://127.0.0.1:3000/wsinit');

_sock.onmessage = function(evt)

alert(evt.data);

};
})(window.x = window.x || { });

Viewing all articles
Browse latest Browse all 6551