When does WebSocket.onmessage start?

(1) Open a connection to WebSocket.

var ws = new WebSocket(url);

(2) When the connection is established, send a message that will trigger a blob response message.

ws.onopen = function () {
    ws.send('1000000');
}

(3) Is it fulfilled onmessagewhen the answer begins or ends?

ws.onmessage = function () {
    // Has the entire blob arrived or has the download just begun?
}
+4
source share
1 answer

The W3C specification for the WebSocket API says that when sending a WebSocket message, it is necessary to send an event message":

When a WebSocket message is received with data type and data, the user agent must queue the task to perform the following actions:

...

  1. , MessageEvent, message, , .

...

  1. WebSocket.

, " WebSocket", RFC 6455, " WebSocket" . WebSockets , :

   , ,    "". .

, 6 RFC 6455, " WebSocket":

    ( 5.4), , _A WebSocket Message Has Been    Received_ // //.     , " "     /data/.    , FIN (frame-fin), , _A     WebSocket //...

, send "", , message.

API- , (, FIN , - finish), message , .

+3

All Articles