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

Side by Side Diff: samples/chat/chat_stress_client.dart

Issue 9653026: Add writeString method to OutputStream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « samples/chat/chat_server_lib.dart ('k') | samples/tests/samples/src/chat/ChatServerTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library("chat_stress_client.dart"); 5 #library("chat_stress_client.dart");
6 #import("dart:io"); 6 #import("dart:io");
7 #import("dart:json"); 7 #import("dart:json");
8 #import("http.dart"); 8 #import("http.dart");
9 9
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 void leave() { 49 void leave() {
50 void leaveResponseHandler(HttpClientResponse response, String data) { 50 void leaveResponseHandler(HttpClientResponse response, String data) {
51 httpClient.shutdown(); 51 httpClient.shutdown();
52 } 52 }
53 53
54 Map leaveRequest = new Map(); 54 Map leaveRequest = new Map();
55 leaveRequest["request"] = "leave"; 55 leaveRequest["request"] = "leave";
56 leaveRequest["sessionId"] = sessionId; 56 leaveRequest["sessionId"] = sessionId;
57 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/leave"); 57 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/leave");
58 conn.onRequest = (HttpClientRequest request) { 58 conn.onRequest = (HttpClientRequest request) {
59 request.writeString(JSON.stringify(leaveRequest)); 59 request.outputStream.writeString(JSON.stringify(leaveRequest));
60 request.outputStream.close(); 60 request.outputStream.close();
61 }; 61 };
62 conn.onResponse = (HttpClientResponse response) { 62 conn.onResponse = (HttpClientResponse response) {
63 StringInputStream stream = new StringInputStream(response.inputStream); 63 StringInputStream stream = new StringInputStream(response.inputStream);
64 StringBuffer body = new StringBuffer(); 64 StringBuffer body = new StringBuffer();
65 stream.onData = () => body.add(stream.read()); 65 stream.onData = () => body.add(stream.read());
66 stream.onClosed = () { 66 stream.onClosed = () {
67 leaveResponseHandler(response, body.toString()); 67 leaveResponseHandler(response, body.toString());
68 }; 68 };
69 }; 69 };
70 } 70 }
71 71
72 var sendMessage; 72 var sendMessage;
73 void receive() { 73 void receive() {
74 void receiveResponseHandler(HttpClientResponse response, String data) { 74 void receiveResponseHandler(HttpClientResponse response, String data) {
75 var responseData = parseResponse(response, data, "receive"); 75 var responseData = parseResponse(response, data, "receive");
76 if (responseData == null) return; 76 if (responseData == null) return;
77 if (responseData["disconnect"] == true) return; 77 if (responseData["disconnect"] == true) return;
78 78
79 sendMessage(); 79 sendMessage();
80 } 80 }
81 81
82 Map messageRequest = new Map(); 82 Map messageRequest = new Map();
83 messageRequest["request"] = "receive"; 83 messageRequest["request"] = "receive";
84 messageRequest["sessionId"] = sessionId; 84 messageRequest["sessionId"] = sessionId;
85 messageRequest["nextMessage"] = receiveMessageCount; 85 messageRequest["nextMessage"] = receiveMessageCount;
86 messageRequest["maxMessages"] = 100; 86 messageRequest["maxMessages"] = 100;
87 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/receive") ; 87 HttpClientConnection conn =
88 httpClient.post("127.0.0.1", port, "/receive");
88 conn.onRequest = (HttpClientRequest request) { 89 conn.onRequest = (HttpClientRequest request) {
89 request.writeString(JSON.stringify(messageRequest)); 90 request.outputStream.writeString(JSON.stringify(messageRequest));
90 request.outputStream.close(); 91 request.outputStream.close();
91 }; 92 };
92 conn.onResponse = (HttpClientResponse response) { 93 conn.onResponse = (HttpClientResponse response) {
93 StringInputStream stream = new StringInputStream(response.inputStream); 94 StringInputStream stream = new StringInputStream(response.inputStream);
94 StringBuffer body = new StringBuffer(); 95 StringBuffer body = new StringBuffer();
95 stream.onData = () => body.add(stream.read()); 96 stream.onData = () => body.add(stream.read());
96 stream.onClosed = () { 97 stream.onClosed = () {
97 receiveResponseHandler(response, body.toString()); 98 receiveResponseHandler(response, body.toString());
98 }; 99 };
99 }; 100 };
(...skipping 14 matching lines...) Expand all
114 receive(); 115 receive();
115 } else { 116 } else {
116 leave(); 117 leave();
117 } 118 }
118 } 119 }
119 120
120 Map messageRequest = new Map(); 121 Map messageRequest = new Map();
121 messageRequest["request"] = "message"; 122 messageRequest["request"] = "message";
122 messageRequest["sessionId"] = sessionId; 123 messageRequest["sessionId"] = sessionId;
123 messageRequest["message"] = "message " + sendMessageCount; 124 messageRequest["message"] = "message " + sendMessageCount;
124 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/message") ; 125 HttpClientConnection conn =
126 httpClient.post("127.0.0.1", port, "/message");
125 conn.onRequest = (HttpClientRequest request) { 127 conn.onRequest = (HttpClientRequest request) {
126 request.writeString(JSON.stringify(messageRequest)); 128 request.outputStream.writeString(JSON.stringify(messageRequest));
127 request.outputStream.close(); 129 request.outputStream.close();
128 }; 130 };
129 conn.onResponse = (HttpClientResponse response) { 131 conn.onResponse = (HttpClientResponse response) {
130 StringInputStream stream = new StringInputStream(response.inputStream); 132 StringInputStream stream = new StringInputStream(response.inputStream);
131 StringBuffer body = new StringBuffer(); 133 StringBuffer body = new StringBuffer();
132 stream.onData = () => body.add(stream.read()); 134 stream.onData = () => body.add(stream.read());
133 stream.onClosed = () { 135 stream.onClosed = () {
134 sendResponseHandler(response, body.toString()); 136 sendResponseHandler(response, body.toString());
135 }; 137 };
136 }; 138 };
137 }; 139 };
138 140
139 void join() { 141 void join() {
140 void joinResponseHandler(HttpClientResponse response, String data) { 142 void joinResponseHandler(HttpClientResponse response, String data) {
141 var responseData = parseResponse(response, data, "join"); 143 var responseData = parseResponse(response, data, "join");
142 if (responseData == null) return; 144 if (responseData == null) return;
143 sessionId = responseData["sessionId"]; 145 sessionId = responseData["sessionId"];
144 146
145 messageCount = 0; 147 messageCount = 0;
146 sendMessageCount = 0; 148 sendMessageCount = 0;
147 receiveMessageCount = 0; 149 receiveMessageCount = 0;
148 sendMessage(); 150 sendMessage();
149 } 151 }
150 152
151 Map joinRequest = new Map(); 153 Map joinRequest = new Map();
152 joinRequest["request"] = "join"; 154 joinRequest["request"] = "join";
153 joinRequest["handle"] = "test1"; 155 joinRequest["handle"] = "test1";
154 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/join"); 156 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/join");
155 conn.onRequest = (HttpClientRequest request) { 157 conn.onRequest = (HttpClientRequest request) {
156 request.writeString(JSON.stringify(joinRequest)); 158 request.outputStream.writeString(JSON.stringify(joinRequest));
157 request.outputStream.close(); 159 request.outputStream.close();
158 }; 160 };
159 conn.onResponse = (HttpClientResponse response) { 161 conn.onResponse = (HttpClientResponse response) {
160 StringInputStream stream = new StringInputStream(response.inputStream); 162 StringInputStream stream = new StringInputStream(response.inputStream);
161 StringBuffer body = new StringBuffer(); 163 StringBuffer body = new StringBuffer();
162 stream.onData = () => body.add(stream.read()); 164 stream.onData = () => body.add(stream.read());
163 stream.onClosed = () { 165 stream.onClosed = () {
164 joinResponseHandler(response, body.toString()); 166 joinResponseHandler(response, body.toString());
165 }; 167 };
166 }; 168 };
167 } 169 }
168 170
169 // Create a HTTP client factory. 171 // Create a HTTP client factory.
170 httpClient = new HttpClient(); 172 httpClient = new HttpClient();
171 port = 8123; 173 port = 8123;
172 174
173 // Start the client by joining the chat topic. 175 // Start the client by joining the chat topic.
174 join(); 176 join();
175 } 177 }
176 178
177 int messagesToSend; 179 int messagesToSend;
178 bool verbose; 180 bool verbose;
179 } 181 }
180 182
181 183
182 void main () { 184 void main () {
183 ChatStressClient stresser = new ChatStressClient(); 185 ChatStressClient stresser = new ChatStressClient();
184 stresser.run(); 186 stresser.run();
185 } 187 }
OLDNEW
« no previous file with comments | « samples/chat/chat_server_lib.dart ('k') | samples/tests/samples/src/chat/ChatServerTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698