This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 23873 - The API is inconsistent with XMLHttpRequest: with the latter you must call .open() or .send() or I don't remember what to actually initiate the connection where here the connection is initiated in the [...]
Summary: The API is inconsistent with XMLHttpRequest: with the latter you must call .o...
Status: RESOLVED WONTFIX
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-20 08:30 UTC by contributor
Modified: 2013-11-25 19:29 UTC (History)
3 users (show)

See Also:


Attachments

Description contributor 2013-11-20 08:30:26 UTC
Specification: http://www.w3.org/TR/2011/WD-websockets-20110929/
Multipage: http://www.whatwg.org/C#top
Complete: http://www.whatwg.org/c#top
Referrer: 

Comment:
The API is inconsistent with XMLHttpRequest: with the latter you must call
.open() or .send() or I don't remember what to actually initiate the
connection where here the connection is initiated in the constructor.
XMLHttpRequest is better in this behaviour because you have the chance to
register event listeners before any state changes, where with WebSocket the
state could already be changed before one has the chance to register any
listeners. I see the section "Feedback from the protocol" says "When the
WebSocket connection is established, the user agent must __queue a task__ to
run these steps", so this queue thing solves the issue I guess but this is
nevertheless bad design and this sentence about the queue feels like a hack.
It is fine with JavaScript because it is single threaded anyway so the
connection process couldn't actually do anything before the code where the
constructor is code is not finished, but this is JavaScript specific and is a
bad design IMO, what if I'm implementing a browser without JavaScript and with
some other, concurrent language? It would be better just to add open method.
It is not a big deal to write new WebSocket("blahblah").open(). BTW it is very
nice that you put this feedback thing here, hope you put it everywhere because
some W3C specs more or less suck and can benefit from feedback. Regards.
Borislav Peev <borislav.asdf@gmail.com>

Posted from: 130.204.166.125
User agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
Comment 1 Ian 'Hixie' Hickson 2013-11-22 18:12:53 UTC
As you note, there's no problem setting handlers before the events are dispatched, because events are queued.

It's not language-specific, any language would have the same model. It's core to the Web model. (We do support multiple threads even now with JS, but the objects remain in one thread at a time, there's no shared state.)

If there was a language which would have trouble with this, we could just provide a different API for that language.

As a general rule, XMLHttpRequest is not considered a great API to emulate.