Re: [hybi] WS framing alternative

Jamie Lokier <jamie@shareable.org> Fri, 30 October 2009 02:53 UTC

Return-Path: <jamie@shareable.org>
X-Original-To: hybi@core3.amsl.com
Delivered-To: hybi@core3.amsl.com
Received: from localhost (localhost [127.0.0.1]) by core3.amsl.com (Postfix) with ESMTP id CC2723A6970 for <hybi@core3.amsl.com>; Thu, 29 Oct 2009 19:53:10 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.829
X-Spam-Level:
X-Spam-Status: No, score=-1.829 tagged_above=-999 required=5 tests=[AWL=-0.470, BAYES_00=-2.599, SARE_LWSHORTT=1.24]
Received: from mail.ietf.org ([64.170.98.32]) by localhost (core3.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UbT7WpGpL0T0 for <hybi@core3.amsl.com>; Thu, 29 Oct 2009 19:53:10 -0700 (PDT)
Received: from mail2.shareable.org (mail2.shareable.org [80.68.89.115]) by core3.amsl.com (Postfix) with ESMTP id E6D7E3A679C for <hybi@ietf.org>; Thu, 29 Oct 2009 19:53:09 -0700 (PDT)
Received: from jamie by mail2.shareable.org with local (Exim 4.63) (envelope-from <jamie@shareable.org>) id 1N3hc9-00074M-5n; Fri, 30 Oct 2009 02:53:21 +0000
Date: Fri, 30 Oct 2009 02:53:21 +0000
From: Jamie Lokier <jamie@shareable.org>
To: Greg Wilkins <gregw@webtide.com>
Message-ID: <20091030025321.GD20292@shareable.org>
References: <8B0A9FCBB9832F43971E38010638454F0F1EA72C@SISPE7MB1.commscope.com> <Pine.LNX.4.62.0910270903080.9145@hixie.dreamhostps.com> <a9699fd20910270426u4aa508cepf557b362025ae5db@mail.gmail.com> <Pine.LNX.4.62.0910271824200.25616@hixie.dreamhostps.com> <4AE76137.8000603@webtide.com> <Pine.LNX.4.62.0910272118590.25608@hixie.dreamhostps.com> <20091029123121.GA24268@almeida.jinsky.com> <4AEA0E6C.1060607@webtide.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
In-Reply-To: <4AEA0E6C.1060607@webtide.com>
User-Agent: Mutt/1.5.13 (2006-08-11)
Cc: hybi@ietf.org
Subject: Re: [hybi] WS framing alternative
X-BeenThere: hybi@ietf.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: Server-Initiated HTTP <hybi.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/hybi>
List-Post: <mailto:hybi@ietf.org>
List-Help: <mailto:hybi-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 30 Oct 2009 02:53:10 -0000

Greg Wilkins wrote:
> It appears that the whatwg want layered protocols to be controlled by
> the allocation of frame byte values to them and only officially
> sanctified extensions will get the nod.

Let's not get confused about what will and won't work.

It doesn't matter whether WHATWG sanctions any new frame type or not:
you can't _use_ a frame type if the other end won't recognise it.

That's because the message boundaries are determined by recognising
the frame type byte, then parsing the message in a type-specific way.

If message boundaries cannot be recognised when an unknown type is
received, a receiver can't do anything more with the connection.  It
just has to drop the connection at that point.

That means any intermediary (which may be just code inside a client or
server framework, or a proxy) will have to pass all all the bytes it
receives as it receives them, with little or no delays, because
intermediaries can't know where a message ends in general, except for
the frame types defined in the first version.

> The Whatwg needs to loosen
> up and realize  that it should not try to completely control how a
> protocol will be used in the wild (eg an not force all servers
> to be 100 line perl scripts).  They have to allow it some room to
> breath and grow.    They need to allocate some space for some
> arbitrary meta data to be used or ignored as implementations see fit.

Implementations can do that themselves.

A curious irony of WebSocket in it's current form is that there's no
reason a particular implementation should bother to use WebSocket
framing, if it doesn't wish to be accessible to Javascript browsers.

Since you must negotiate any custom protocol layered on top of
WebSocket out of band anyway (e.g. by agreeing what is present on some
URL), and because message boundaries cannot be recognised for unknown
frame types, and because there is no way to report per-frame errors,
in general all software which doesn't block WebSocket and intends to
be future compatible must pass the byte stream along verbatim, without
delays.

That means when implementing clients and servers of custom protocols,
you have two choices:

    - You want it to be accessible to Javascript in web browsers (in
      the short term future).  So you must frame everything into UTF-8
      frames, whatever kind of data it is, and define your own text
      protocol within that.

    - You don't care about Javascript in web browsers.  Because you
      know anything forwarding your WebSocket connection which is
      future compatible must pass along arbitrary bytes without
      delays, because there is no generic way for it to know frame
      lengths, you might as well send frame type byte NN (pick a
      number that is not used) followed by raw TCP with your own
      protocol after the upgrade request, if that is convenient.

      There seems to be no reason to use the spec's binary frames, if
      a TCP stream is more convenient for some application.

-- Jamie