OLD | NEW |
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 /** | 5 /** |
6 * File, socket, HTTP, and other I/O support for server applications. | 6 * File, socket, HTTP, and other I/O support for server applications. |
7 * | 7 * |
8 * The I/O library is used for Dart server applications, | 8 * The I/O library is used for Dart server applications, |
9 * which run on a stand-alone Dart VM from the command line. | 9 * which run on a stand-alone Dart VM from the command line. |
10 * *This library does not work in browser-based applications.* | 10 * *This library does not work in browser-based applications.* |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 * the native machine. | 73 * the native machine. |
74 * For example, the following code spawns a process that recursively lists | 74 * For example, the following code spawns a process that recursively lists |
75 * the files under `web`. | 75 * the files under `web`. |
76 * | 76 * |
77 * Process.start('ls', ['-R', 'web']).then((process) { | 77 * Process.start('ls', ['-R', 'web']).then((process) { |
78 * stdout.addStream(process.stdout); | 78 * stdout.addStream(process.stdout); |
79 * stderr.addStream(process.stderr); | 79 * stderr.addStream(process.stderr); |
80 * process.exitCode.then(print); | 80 * process.exitCode.then(print); |
81 * }); | 81 * }); |
82 * | 82 * |
83 * Using `start()` returns a Future, which completes with a [Process] object whe
n | 83 * Using `start()` returns a Future, which completes with a [Process] object |
84 * the process has started. This [Process] object allows you to interact with th
e | 84 * when the process has started. This [Process] object allows you to interact |
85 * process while it is running. Using `run()` returns a Future, which completes
with | 85 * with the process while it is running. Using `run()` returns a Future, which |
86 * a [ProcessResult] object when the spawned process has terminated. This | 86 * completes with a [ProcessResult] object when the spawned process has |
87 * [ProcessResult] object collects the output and exit code from the process. | 87 * terminated. This [ProcessResult] object collects the output and exit code |
| 88 * from the process. |
88 * | 89 * |
89 * When using `start()`, | 90 * When using `start()`, |
90 * you need to read all data coming on the stdout and stderr streams otherwise | 91 * you need to read all data coming on the stdout and stderr streams otherwise |
91 * the system resources will not be freed. | 92 * the system resources will not be freed. |
92 * | 93 * |
93 * ## WebSocket | 94 * ## WebSocket |
94 * | 95 * |
95 * The [WebSocket] class provides support for the web socket protocol. This allo
ws | 96 * The [WebSocket] class provides support for the web socket protocol. This |
96 * full-duplex communications between client and server applications. | 97 * allows full-duplex communications between client and server applications. |
97 * Use the WebSocket class in the `dart:html` library for web clients. | 98 * Use the WebSocket class in the `dart:html` library for web clients. |
98 * | 99 * |
99 * A web socket server uses a normal HTTP server for accepting web socket | 100 * A web socket server uses a normal HTTP server for accepting web socket |
100 * connections. The initial handshake is a HTTP request which is then upgraded t
o a | 101 * connections. The initial handshake is a HTTP request which is then upgraded t
o a |
101 * web socket connection. | 102 * web socket connection. |
102 * The server upgrades the request using [WebSocketTransformer] | 103 * The server upgrades the request using [WebSocketTransformer] |
103 * and listens for the data on the returned web socket. | 104 * and listens for the data on the returned web socket. |
104 * For example, here's a mini server that listens for 'ws' data | 105 * For example, here's a mini server that listens for 'ws' data |
105 * on a WebSocket: | 106 * on a WebSocket: |
106 * | 107 * |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 * | 141 * |
141 * ServerSocket.bind('127.0.0.1', 4041) | 142 * ServerSocket.bind('127.0.0.1', 4041) |
142 * .then((serverSocket) { | 143 * .then((serverSocket) { |
143 * serverSocket.listen((socket) { | 144 * serverSocket.listen((socket) { |
144 * socket.transform(UTF8.decoder).listen(print); | 145 * socket.transform(UTF8.decoder).listen(print); |
145 * }); | 146 * }); |
146 * }); | 147 * }); |
147 * | 148 * |
148 * A client connects a Socket using the `connect()` method, | 149 * A client connects a Socket using the `connect()` method, |
149 * which returns a Future. | 150 * which returns a Future. |
150 * Using `write()`, `writeln()`, or `writeAll()` are the easiest ways to | 151 * Using `write()`, `writeln()`, or `writeAll()` are the easiest ways to |
151 * send data over the socket. | 152 * send data over the socket. |
152 * For example: | 153 * For example: |
153 * | 154 * |
154 * Socket.connect('127.0.0.1', 4041).then((socket) { | 155 * Socket.connect('127.0.0.1', 4041).then((socket) { |
155 * socket.write('Hello, World!'); | 156 * socket.write('Hello, World!'); |
156 * }); | 157 * }); |
157 * | 158 * |
158 * Besides [Socket] and [ServerSocket], the [RawSocket] and | 159 * Besides [Socket] and [ServerSocket], the [RawSocket] and |
159 * [RawServerSocket] classes are available for lower-level access | 160 * [RawServerSocket] classes are available for lower-level access |
160 * to async socket IO. | 161 * to async socket IO. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 part 'platform_impl.dart'; | 230 part 'platform_impl.dart'; |
230 part 'process.dart'; | 231 part 'process.dart'; |
231 part 'socket.dart'; | 232 part 'socket.dart'; |
232 part 'stdio.dart'; | 233 part 'stdio.dart'; |
233 part 'string_transformer.dart'; | 234 part 'string_transformer.dart'; |
234 part 'timer_impl.dart'; | 235 part 'timer_impl.dart'; |
235 part 'secure_socket.dart'; | 236 part 'secure_socket.dart'; |
236 part 'secure_server_socket.dart'; | 237 part 'secure_server_socket.dart'; |
237 part 'websocket.dart'; | 238 part 'websocket.dart'; |
238 part 'websocket_impl.dart'; | 239 part 'websocket_impl.dart'; |
OLD | NEW |