Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(909)

Side by Side Diff: src/site/_includes/library-tour/html-websockets.markdown

Issue 10910215: fix bugs in docs (Closed) Base URL: git@github.com:dart-lang/dartlang.org.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/site/articles/improving-the-dom/index.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 ### WebSockets {#html-websockets} 1 ### WebSockets {#html-websockets}
2 2
3 A WebSocket allows your web app to exchange data with a server interactively&mda sh;no 3 A WebSocket allows your web app to exchange data with a server interactively&mda sh;no
4 polling necessary. 4 polling necessary.
5 A server creates the WebSocket and listens for requests on 5 A server creates the WebSocket and listens for requests on
6 a URL that starts with **ws://**—for example, 6 a URL that starts with **ws://**—for example,
7 ws://127.0.0.1:1337/ws. 7 ws://127.0.0.1:1337/ws.
8 The data transmitted over a WebSocket can be 8 The data transmitted over a WebSocket can be
9 a string, a blob, or an 9 a string, a blob, or an
10 [ArrayBuffer](http://api.dartlang.org/html/ArrayBuffer.html). 10 [ArrayBuffer](http://api.dartlang.org/html/ArrayBuffer.html).
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 Here's an example of a method that 70 Here's an example of a method that
71 creates a WebSocket object 71 creates a WebSocket object
72 and handles message, open, close, and error events. 72 and handles message, open, close, and error events.
73 73
74 {% highlight dart %} 74 {% highlight dart %}
75 connectToWebSocket([int retrySeconds = 2]) { 75 connectToWebSocket([int retrySeconds = 2]) {
76 bool encounteredError = false; 76 bool encounteredError = false;
77 webSocket = new WebSocket(url); 77 webSocket = new WebSocket(url);
78 78
79 webSocket.on.message.add((e) { 79 webSocket.on.message.add((e) {
80 receivedMessage(e.data); 80 receivedMessage((e as MessageEvent).data);
81 }); 81 });
82 82
83 webSocket.on.open.add((e) { 83 webSocket.on.open.add((e) {
84 print('Connected'); 84 print('Connected');
85 }); 85 });
86 86
87 webSocket.on.close.add((e) { 87 webSocket.on.close.add((e) {
88 print('web socket closed, retrying in $retrySeconds seconds'); 88 print('web socket closed, retrying in $retrySeconds seconds');
89 if (!encounteredError) { 89 if (!encounteredError) {
90 window.setTimeout(() => connectToWebSocket(retrySeconds*2), 90 window.setTimeout(() => connectToWebSocket(retrySeconds*2),
91 1000*retrySeconds); 91 1000*retrySeconds);
92 } 92 }
93 encounteredError = true; 93 encounteredError = true;
94 }); 94 });
95 95
96 webSocket.on.error.add((e) { 96 webSocket.on.error.add((e) {
97 chatWindow.displayNotice('Error connecting to ws'); 97 chatWindow.displayNotice('Error connecting to ws');
98 if (!encounteredError) { 98 if (!encounteredError) {
99 window.setTimeout(() => connectToWebSocket(retrySeconds*2), 99 window.setTimeout(() => connectToWebSocket(retrySeconds*2),
100 1000*retrySeconds); 100 1000*retrySeconds);
101 } 101 }
102 encounteredError = true; 102 encounteredError = true;
103 }); 103 });
104 } 104 }
105 {% endhighlight %} 105 {% endhighlight %}
OLDNEW
« no previous file with comments | « no previous file | src/site/articles/improving-the-dom/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698