- From: poot <cvsmail@w3.org>
- Date: Wed, 02 May 2012 15:50:10 -0400
- To: public-html-diffs@w3.org
websocket; hixie: add websocket onmessage example (whatwg r7082) http://dev.w3.org/cvsweb/html5/websockets/Overview.html?r1=1.262&r2=1.263&f=h http://html5.org/tools/web-apps-tracker?from=7081&to=7082 =================================================================== RCS file: /sources/public/html5/websockets/Overview.html,v retrieving revision 1.262 retrieving revision 1.263 diff -u -d -r1.262 -r1.263 --- Overview.html 2 May 2012 19:46:32 -0000 1.262 +++ Overview.html 2 May 2012 19:50:03 -0000 1.263 @@ -1002,6 +1002,24 @@ data back to RAM before running this <span title="concept-task">task</span> so as to avoid stalling the main thread while it created the <code>ArrayBuffer</code> object.</p> + <div class="example"> + + <p>Here is an example of how to define a handler for the <code title="event-message">message</code> event in the case of text + frames:</p> + + <pre>mysocket.onmessage = function (event) { + if (event.data == 'on') { + turnLampOn(); + } else if (event.data == 'off') { + turnLampOff(); + } +};</pre> + + <p>The protocol here is a trivial one, with the server just sending + "on" or "off" messages.</p> + + </div> + <hr><p>When <i>the WebSocket closing handshake is started</i>, the user agent must <span>queue a task</span> to change the <code title="dom-WebSocket-readyState"><a href="#dom-websocket-readystate">readyState</a></code> attribute's value to <code title="dom-WebSocket-CLOSING"><a href="#dom-websocket-closing">CLOSING</a></code> (2). (If the
Received on Wednesday, 2 May 2012 19:50:12 UTC