Determine if websocket send () is complete

Is there a way to get notified if a specific send() complete? As I noticed, the send() function does not block, but the code is continuous. Is there an easy way to block or receive a notification that the transfer is complete?

+6
source share
1 answer

You can 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, execute a confirmation response from the server for each client message (after trying, it works fine)

+3
source

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


All Articles