<span class="Apple-style-span" style="-webkit-text-stroke: none; -webkit-transform-origin-z: 0px; -webkit-transform-style: 50%; ">On Thu, Nov 19, 2009 at 1:00 PM, Greg Wilkins <span dir="ltr"><<a href="mailto:gregw@webtide.com">gregw@webtide.com</a>></span> wrote:</span><br>

<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
Is there a race in the websocket API.<br>
<br>
When you do:<br>
<br>
  var ws = new WebSocket("ws://<a href="http://mysite.com" target="_blank">mysite.com</a>","myprotocol");<br>
<br>
then the spec says:<br>
<br>
   Return a new WebSocket object, and continue these steps in the<br>
   background (without blocking scripts).<br>
<br>
   Establish a Web Socket connection to a host host, on port port<br>
   (if one was specified), from origin, with the flag secure, with<br>
   resource name as the resource name, and with protocol as the<br>
   protocol (if it is present).<br>
<br>
<br>
So if the next line in the script is<br>
<br>
  ws.onopen=myopenfunc;<br>
<br>
there is a race between if the onopen function will<br>
be assigned and if the background connection has been established?<br></blockquote><div><br></div><span class="Apple-style-span" style="font-family: arial, sans-serif; -webkit-text-stroke: none; -webkit-transform-origin-z: 0px; -webkit-transform-style: 50%; font-size: 13px; border-collapse: collapse; "><div>

I believe open event  is just queued at the moment, and it will be fired later when javascript becomes idle.</div><div><br></div><div><div>When the Web Socket connection is established, the user agent must run the following steps:</div>

<div><span> Change the readyState attribute's value to OPEN (1).</span></div><div><span> Queue a task to fire a simple event named open at the WebSocket object.</span></div></div><div><br></div><div>-- </div></span><div>

<span class="Apple-style-span" style="font-family: arial, sans-serif; -webkit-text-stroke: none; -webkit-transform-origin-z: 0px; -webkit-transform-style: 50%; font-size: 13px; border-collapse: collapse; ">ukai</span> </div>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
OK it is currently unlikely that the connect will happen that<br>
quick - however if I'm running in a rhino test environment<br>
or a on a browser that is multiplexing the websocket onto an<br>
already existing connection, then the onopen may indeed be fast.<br>
<br>
Similar races exist for onmessage and onclose.  Setting onmessage<br>
might miss a message that is delivered quickly after the websocket<br>
is opened.<br>
<br>
<br>
regards<br>
_______________________________________________<br>
hybi mailing list<br>
<a href="mailto:hybi@ietf.org">hybi@ietf.org</a><br>
<a href="https://www.ietf.org/mailman/listinfo/hybi" target="_blank">https://www.ietf.org/mailman/listinfo/hybi</a><br>
</blockquote></div><br>