Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if a websocket send() is finished

Is there a way to get notified if a certain send() has finished? As i noticed the send() function is not blocking and the code continuous. Is there a simple way to either make it blocking or getting somehow notified if the send is finished?

like image 242
dustin.b Avatar asked Aug 12 '13 14:08

dustin.b


1 Answers

You could rely on Socket.bufferedamount (never tried)

http://www.whatwg.org/specs/web-apps/current-work/multipage/network.html#dom-websocket-bufferedamount

var socket = new WebSocket('ws://game.example.com:12010/updates');
socket.onopen = function () {
    setInterval(function() {
        if (socket.bufferedAmount == 0){
          // Im' not busy anymore - set a flag or something like that
        }
    }, 50);
};

Or implement an acknowledge answer from the server for every client message (tried, works fine)

like image 119
mguimard Avatar answered Oct 05 '22 08:10

mguimard