Re: Web Sockets API, buffer handling after the connection is closed

Throwing will likely lead to sites breaking since it's likely that
many will not expect connections to get broken due to network issues.

Having bufferedAmount continuously increase seem to address the
example code you included. Or more generally, code that does:

if (socket.bufferedAmount < X)
  sendStuff(socket);

Note that you don't have to actually buffer anything. I.e. you can
just throw away the data that is sent and increase bufferedAmount with
the size of the data.

/ Jonas

On Thu, Feb 18, 2010 at 4:56 AM, Olli Pettay <Olli.Pettay@helsinki.fi> wrote:
> Hi,
>
> I wonder why send() needs to buffer anything after the connection is closed.
> bufferedAmount is defined: "If the connection is closed, this attribute's
> value will only increase with each call to the send() method (the number
> does not reset to zero once the connection closes)"
>
> Why not clear the buffer right after dispatching close event and then
> throw if send() is called, or something similar?
>
> Or is the current behavior there just so that the example works;
> send new data whenever socket.bufferedAmount == 0. (Though the send may not
> actually send the data ever)
>
> The example could be a bit different
> var socket = new WebSocket('ws://game.example.com:12010/updates');
> socket.onopen = function () {
>  setInterval(function() {
>    if (socket.readyState == WebSocket.OPEN && socket.bufferedAmount == 0)
>      socket.send(getUpdateData());
>  }, 50);
> };
>
>
>
> -Olli
>
>

Received on Thursday, 18 February 2010 21:49:55 UTC