[whatwg] Add connect() to TCPConnection
Michael Carter
michael.carter at kaazing.com
Thu Apr 24 16:51:57 PDT 2008
Currently, the TCPConnection constructor implicitly opens a tcp connection.
One downside to this is that a user of the api couldn't re-use the
TCPConnection object for future connections. XMLHttpRequest on the other
hand has open() and abort() methods. The same duality should exist for
TCPConnection, thus allowing for re-use. A secondary concern is that the
usage of the API is tied to the execution model of javascript with respect
to concurrency. That is to say, the only good time to attach an onopen,
onclose, or onread callback to the TCPConnection object is immediately
following its creation. While this may not be a problem and could certainly
be worked around in most cases, adding connect() would allow these callbacks
to be attached at any point after the creation of the object, but before the
explict call to connect().
The proposal then is to make the following changes:
1) The TCPConnection() constructor should take no arguments
2) TCPConnection should expose an additional method, connect(subdomain,
port, secure), that has a method signature identical to the old constructor
3) An additional readyState value be added to the Connection interface, such
that the following values have the following meanings:
readyState 0: initialized
readyState 1: connecting
readyState 2: connected
readyState 3: closed
4) valid state transitions are in increasing numerical order, or from 3 -> 1
when connect() is called in a closed state.
An example of using the new TCPConnection is as follows
var tcp = new TCPConnection()
tcp.onopen = function(evt) { alert('opened!') }
tcp.onclose = function(evt) { alert('opened!') }
tcp.onread = function(evt) { alert('read: ' + evt.data) }
tcp.connect("testing", 443) // Connect to testing.domain.com:443
And an example of re-using the TCPConnection object
tcp.disconnect()
tcp.onopen = function(evt) { alert('opened again!') }
tcp.onclose = function(evt) { alert('opened again!') }
tcp.onread = function(evt) { alert('read (again): ' + evt.data) }
tcp.connect("testing2", 443) // Connect to testing2.domain.com:443
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20080424/d97cfba3/attachment-0001.htm>
More information about the whatwg
mailing list