OLD | NEW |
1 The `web_socket_channel` package provides [`StreamChannel`][stream_channel] | 1 The `web_socket_channel` package provides [`StreamChannel`][stream_channel] |
2 wrappers for WebSocket connections. It provides a cross-platform | 2 wrappers for WebSocket connections. It provides a cross-platform |
3 [`WebSocketChannel`][WebSocketChannel] API, a cross-platform implementation of | 3 [`WebSocketChannel`][WebSocketChannel] API, a cross-platform implementation of |
4 that API that communicates over an underlying [`StreamChannel`][stream_channel], | 4 that API that communicates over an underlying [`StreamChannel`][stream_channel], |
5 and [an implementation][IOWebSocketChannel] that wraps `dart:io`'s `WebSocket` | 5 and [an implementation][IOWebSocketChannel] that wraps `dart:io`'s `WebSocket` |
6 class. | 6 class. |
7 | 7 |
8 [stream_channel]: https://pub.dartlang.org/packages/stream_channel | 8 [stream_channel]: https://pub.dartlang.org/packages/stream_channel |
9 [WebSocketChannel]: https://www.dartdocs.org/documentation/web_socket_channel/la
test/web_socket_channel/WebSocketChannel-class.html | 9 [WebSocketChannel]: https://www.dartdocs.org/documentation/web_socket_channel/la
test/web_socket_channel/WebSocketChannel-class.html |
10 [IOWebSocketChannel]: https://www.dartdocs.org/documentation/web_socket_channel/
latest/io/IOWebSocketChannel-class.html | 10 [IOWebSocketChannel]: https://www.dartdocs.org/documentation/web_socket_channel/
latest/io/IOWebSocketChannel-class.html |
11 | 11 |
12 ## `WebSocketChannel` | 12 ## `WebSocketChannel` |
13 | 13 |
14 The [`WebSocketChannel`][WebSocketChannel] class's most important role is as the | 14 The [`WebSocketChannel`][WebSocketChannel] class's most important role is as the |
15 interface for WebSocket stream channels across all implementations and all | 15 interface for WebSocket stream channels across all implementations and all |
16 platforms. In addition to the base `StreamChannel` interface, it adds a | 16 platforms. In addition to the base `StreamChannel` interface, it adds a |
17 [`protocol`][protocol] getter that returns the negotiated protocol for the | 17 [`protocol`][protocol] getter that returns the negotiated protocol for the |
18 socket; a [`pingInterval`][pingInterval] property that allows you to control the | 18 socket, as well as [`closeCode`][closeCode] and [`closeReason`][closeReason] |
19 socket's keep-alive behavior; and [`closeCode`][closeCode] and | 19 getters that provide information about why the socket closed. |
20 [`closeReason`][closeReason] getters that provide information about why the | |
21 socket closed. | |
22 | 20 |
23 [protocol]: https://www.dartdocs.org/documentation/web_socket_channel/latest/web
_socket_channel/WebSocketChannel/protocol.html | 21 [protocol]: https://www.dartdocs.org/documentation/web_socket_channel/latest/web
_socket_channel/WebSocketChannel/protocol.html |
24 [pingInterval]: https://www.dartdocs.org/documentation/web_socket_channel/latest
/web_socket_channel/WebSocketChannel/pingInterval.html | |
25 [closeCode]: https://www.dartdocs.org/documentation/web_socket_channel/latest/we
b_socket_channel/WebSocketChannel/closeCode.html | 22 [closeCode]: https://www.dartdocs.org/documentation/web_socket_channel/latest/we
b_socket_channel/WebSocketChannel/closeCode.html |
26 [closeReason]: https://www.dartdocs.org/documentation/web_socket_channel/latest/
web_socket_channel/WebSocketChannel/closeReason.html | 23 [closeReason]: https://www.dartdocs.org/documentation/web_socket_channel/latest/
web_socket_channel/WebSocketChannel/closeReason.html |
27 | 24 |
28 The channel's [`sink` property][sink] is also special. It returns a | 25 The channel's [`sink` property][sink] is also special. It returns a |
29 [`WebSocketSink`][WebSocketSink], which is just like a `StreamSink` except that | 26 [`WebSocketSink`][WebSocketSink], which is just like a `StreamSink` except that |
30 its [`close()`][sink.close] method supports optional `closeCode` and | 27 its [`close()`][sink.close] method supports optional `closeCode` and |
31 `closeReason` parameters. These parameters allow the caller to signal to the | 28 `closeReason` parameters. These parameters allow the caller to signal to the |
32 other socket exactly why they're closing the connection. | 29 other socket exactly why they're closing the connection. |
33 | 30 |
34 [sink]: https://www.dartdocs.org/documentation/web_socket_channel/latest/web_soc
ket_channel/WebSocketChannel/sink.html | 31 [sink]: https://www.dartdocs.org/documentation/web_socket_channel/latest/web_soc
ket_channel/WebSocketChannel/sink.html |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 import 'package:web_socket_channel/io.dart'; | 67 import 'package:web_socket_channel/io.dart'; |
71 | 68 |
72 main() async { | 69 main() async { |
73 var channel = new IOWebSocketChannel.connect("ws://localhost:8181"); | 70 var channel = new IOWebSocketChannel.connect("ws://localhost:8181"); |
74 channel.sink.add("connected!"); | 71 channel.sink.add("connected!"); |
75 channel.sink.listen((message) { | 72 channel.sink.listen((message) { |
76 // ... | 73 // ... |
77 }); | 74 }); |
78 } | 75 } |
79 ``` | 76 ``` |
OLD | NEW |