W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2010

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

From: Jonas Sicking <jonas@sicking.cc>
Date: Thu, 18 Feb 2010 13:48:58 -0800
Message-ID: <63df84f1002181348u73ab747ehe7513a830b27527b@mail.gmail.com>
To: Olli@pettay.fi
Cc: public-webapps@w3.org, Ian Hickson <ian@hixie.ch>
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:37 GMT