W3C home > Mailing lists > Public > public-html-commits@w3.org > May 2012

html5/websockets Overview.html,1.262,1.263

From: Ian Hickson via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 02 May 2012 19:50:05 +0000
To: public-html-commits@w3.org
Message-Id: <E1SPfYr-0005DE-Lh@lionel-hutz.w3.org>
Update of /sources/public/html5/websockets
In directory hutz:/tmp/cvs-serv20022

Modified Files:
	Overview.html 
Log Message:
add websocket onmessage example (whatwg r7082)

Index: Overview.html
===================================================================
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:08 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 2 May 2012 19:50:08 GMT