OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 | 7 |
8 /** | 8 /** |
9 * [InternetAddressType] is the type an [InternetAddress]. Currently, | 9 * [InternetAddressType] is the type an [InternetAddress]. Currently, |
10 * IP version 4 (IPv4) and IP version 6 (IPv6) are supported. | 10 * IP version 4 (IPv4) and IP version 6 (IPv6) are supported. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 * addresses. If [type] is either [InternetAddressType.IP_V4] or | 93 * addresses. If [type] is either [InternetAddressType.IP_V4] or |
94 * [InternetAddressType.IP_V6] it will only lookup addresses of the | 94 * [InternetAddressType.IP_V6] it will only lookup addresses of the |
95 * specified type. The order of the list can, and most likely will, | 95 * specified type. The order of the list can, and most likely will, |
96 * change over time. | 96 * change over time. |
97 */ | 97 */ |
98 external static Future<List<InternetAddress>> lookup( | 98 external static Future<List<InternetAddress>> lookup( |
99 String host, {InternetAddressType type: InternetAddressType.IP_V4}); | 99 String host, {InternetAddressType type: InternetAddressType.IP_V4}); |
100 } | 100 } |
101 | 101 |
102 /** | 102 /** |
103 * The RawServerSocket is a server socket, providing a stream of low-level | 103 * A [RawServerSocket] represents a listening socket, and provides a |
104 * [RawSocket]s. | 104 * stream of low-level [RawSocket] objects, one for each connection |
| 105 * made to the listening socket. |
105 * | 106 * |
106 * See [RawSocket] for more info. | 107 * See [RawSocket] for more info. |
107 */ | 108 */ |
108 abstract class RawServerSocket implements Stream<RawSocket> { | 109 abstract class RawServerSocket implements Stream<RawSocket> { |
109 /** | 110 /** |
110 * Returns a future for a [:RawServerSocket:]. When the future | 111 * Returns a future for a [:RawServerSocket:]. When the future |
111 * completes the server socket is bound to the given [address] and | 112 * completes the server socket is bound to the given [address] and |
112 * [port] and has started listening on it. | 113 * [port] and has started listening on it. |
113 * | 114 * |
114 * The default value for [address] is 127.0.0.1, which will allow | 115 * The [address] can either be a [String] or an |
115 * only incoming connections from the local host. To allow for | 116 * [InternetAddress]. If [address] is a [String], [bind] will |
116 * incoming connection from the network use either the value 0.0.0.0 | 117 * perform a [InternetAddress.lookup] and use the first value in the |
117 * to bind to all interfaces or the IP address of a specific | 118 * list. To listen on the loopback adapter, which will allow only |
118 * interface. | 119 * incoming connections from the local host, use the value |
| 120 * [InternetAddress.LOOPBACK_IP_V4] or |
| 121 * [InternetAddress.LOOPBACK_IP_V6]. To allow for incoming |
| 122 * connection from the network use either one of the values |
| 123 * [InternetAddress.ANY_IP_V4] or [InternetAddress.ANY_IP_V6] to |
| 124 * bind to all interfaces or the IP address of a specific interface. |
119 * | 125 * |
120 * If [port] has the value [:0:] (the default) an ephemeral port will | 126 * If an IP version 6 (IPv6) address is used, both IP version 6 |
| 127 * (IPv6) and version 4 (IPv4) connections will be accepted. To |
| 128 * restrict this to version 6 (IPv6) only, use [setOption] to set |
| 129 * version 6 only. |
| 130 * |
| 131 * If [port] has the value [:0:] an ephemeral port will |
121 * be chosen by the system. The actual port used can be retrieved | 132 * be chosen by the system. The actual port used can be retrieved |
122 * using the [:port:] getter. | 133 * using the [:port:] getter. |
123 * | 134 * |
124 * The optional argument [backlog] can be used to specify the listen | 135 * The optional argument [backlog] can be used to specify the listen |
125 * backlog for the underlying OS listen setup. If [backlog] has the | 136 * backlog for the underlying OS listen setup. If [backlog] has the |
126 * value of [:0:] (the default) a reasonable value will be chosen by | 137 * value of [:0:] (the default) a reasonable value will be chosen by |
127 * the system. | 138 * the system. |
128 */ | 139 */ |
129 external static Future<RawServerSocket> bind([address = "127.0.0.1", | 140 external static Future<RawServerSocket> bind(address, |
130 int port = 0, | 141 int port, |
131 int backlog = 0]); | 142 {int backlog: 0}); |
132 | 143 |
133 /** | 144 /** |
134 * Returns the port used by this socket. | 145 * Returns the port used by this socket. |
135 */ | 146 */ |
136 int get port; | 147 int get port; |
137 | 148 |
138 /** | 149 /** |
139 * Closes the socket. | 150 * Closes the socket. |
140 */ | 151 */ |
141 void close(); | 152 void close(); |
142 } | 153 } |
143 | 154 |
144 | 155 |
145 /** | 156 /** |
146 * The [ServerSocket] is server socket, providing a stream of high-level | 157 * A [ServerSocket] represents a listening socket, and provides a |
147 * [Socket]s. | 158 * stream of [Socket] objects, one for each connection made to the |
| 159 * listening socket. |
148 * | 160 * |
149 * See [Socket] for more info. | 161 * See [Socket] for more info. |
150 */ | 162 */ |
151 abstract class ServerSocket implements Stream<Socket> { | 163 abstract class ServerSocket implements Stream<Socket> { |
152 /** | 164 /** |
153 * Returns a future for a [:ServerSocket:]. When the future | 165 * Returns a future for a [:ServerSocket:]. When the future |
154 * completes the server socket is bound to the given [address] and | 166 * completes the server socket is bound to the given [address] and |
155 * [port] and has started listening on it. | 167 * [port] and has started listening on it. |
156 * | 168 * |
157 * The default value for [address] is 127.0.0.1, which will allow | 169 * The [address] can either be a [String] or an |
158 * only incoming connections from the local host. To allow for | 170 * [InternetAddress]. If [address] is a [String], [bind] will |
159 * incoming connection from the network use either the value 0.0.0.0 | 171 * perform a [InternetAddress.lookup] and use the first value in the |
160 * to bind to all interfaces or the IP address of a specific | 172 * list. To listen on the loopback adapter, which will allow only |
161 * interface. | 173 * incoming connections from the local host, use the value |
| 174 * [InternetAddress.LOOPBACK_IP_V4] or |
| 175 * [InternetAddress.LOOPBACK_IP_V6]. To allow for incoming |
| 176 * connection from the network use either one of the values |
| 177 * [InternetAddress.ANY_IP_V4] or [InternetAddress.ANY_IP_V6] to |
| 178 * bind to all interfaces or the IP address of a specific interface. |
162 * | 179 * |
163 * If [port] has the value [:0:] (the default) an ephemeral port will | 180 * If an IP version 6 (IPv6) address is used, both IP version 6 |
164 * be chosen by the system. The actual port used can be retrieved | 181 * (IPv6) and version 4 (IPv4) connections will be accepted. To |
165 * using the [port] getter. | 182 * restrict this to version 6 (IPv6) only, use [setOption] to set |
| 183 * version 6 only. |
| 184 * |
| 185 * If [port] has the value [:0:] an ephemeral port will be chosen by |
| 186 * the system. The actual port used can be retrieved using the |
| 187 * [port] getter. |
166 * | 188 * |
167 * The optional argument [backlog] can be used to specify the listen | 189 * The optional argument [backlog] can be used to specify the listen |
168 * backlog for the underlying OS listen setup. If [backlog] has the | 190 * backlog for the underlying OS listen setup. If [backlog] has the |
169 * value of [:0:] (the default) a reasonable value will be chosen by | 191 * value of [:0:] (the default) a reasonable value will be chosen by |
170 * the system. | 192 * the system. |
171 */ | 193 */ |
172 external static Future<ServerSocket> bind([address = "127.0.0.1", | 194 external static Future<ServerSocket> bind(address, |
173 int port = 0, | 195 int port, |
174 int backlog = 0]); | 196 {int backlog: 0}); |
175 | 197 |
176 /** | 198 /** |
177 * Returns the port used by this socket. | 199 * Returns the port used by this socket. |
178 */ | 200 */ |
179 int get port; | 201 int get port; |
180 | 202 |
181 /** | 203 /** |
182 * Closes the socket. | 204 * Closes the socket. |
183 */ | 205 */ |
184 void close(); | 206 void close(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 sb.write(" ($osError)"); | 418 sb.write(" ($osError)"); |
397 } | 419 } |
398 } else if (osError != null) { | 420 } else if (osError != null) { |
399 sb.write(": $osError"); | 421 sb.write(": $osError"); |
400 } | 422 } |
401 return sb.toString(); | 423 return sb.toString(); |
402 } | 424 } |
403 final String message; | 425 final String message; |
404 final OSError osError; | 426 final OSError osError; |
405 } | 427 } |
OLD | NEW |