Short URL: http://html5.org/r/4638
| SVN | Bug | Comment | Time (UTC) |
|---|---|---|---|
| 4638 | Add a bufferedAmount example. | 2010-01-31 07:53 |
Index: source
===================================================================
--- source (revision 4637)
+++ source (revision 4638)
@@ -76195,6 +76195,32 @@
title="dom-WebSocket-send">send()</code> method (the number does not
reset to zero once the connection closes).</p>
+ <div class="example">
+
+ <p>In this simple example, the <code
+ title="dom-WebSocket-bufferedAmount">bufferedAmount</code>
+ attribute is used to ensure that updates are sent either at the
+ rate of one update every 50ms, if the network can handle that rate,
+ or at whatever rate the network <em>can</em> handle, if that is too
+ fast.</p>
+
+ <pre>var socket = new WebSocket('ws://game.example.com:12010/updates');
+socket.onopen = function () {
+ setInterval(function() {
+ if (socket.bufferedAmount == 0)
+ socket.send(getUpdateData());
+ }, 50);
+};</pre>
+
+ <p>The <code
+ title="dom-WebSocket-bufferedAmount">bufferedAmount</code>
+ attribute can also be used to saturate the network without sending
+ the data at a higher rate than the network can handle, though this
+ requires more careful monitoring of the value of the attribute over
+ time.</p>
+
+ </div>
+
<hr>
<p>The following are the <span>event handlers</span> that must be