@@ -46,6 +46,31 @@ void main() async {
46
46
}
47
47
```
48
48
49
+ [ CupertinoWebSocket] [ ] provides a [ package: web_socket ] [ ] [ WebSocket] [ ]
50
+ implementation.
51
+
52
+ ``` dart
53
+ import 'package:cupertino_http/cupertino_http.dart';
54
+ import 'package:web_socket/web_socket.dart';
55
+
56
+ void main() async {
57
+ final socket = await CupertinoWebSocket.connect(
58
+ Uri.parse('wss://ws.postman-echo.com/raw'));
59
+
60
+ socket.events.listen((e) async {
61
+ switch (e) {
62
+ case TextDataReceived(text: final text):
63
+ print('Received Text: $text');
64
+ await socket.close();
65
+ case BinaryDataReceived(data: final data):
66
+ print('Received Binary: $data');
67
+ case CloseReceived(code: final code, reason: final reason):
68
+ print('Connection to server closed: $code [$reason]');
69
+ }
70
+ });
71
+ }
72
+ ```
73
+
49
74
You can also use the [ Foundation URL Loading System] API directly.
50
75
51
76
``` dart
@@ -63,6 +88,9 @@ final task = session.dataTaskWithCompletionHandler(URLRequest.fromUrl(url),
63
88
task.resume();
64
89
```
65
90
66
- [ package:http Client ] : https://pub.dev/documentation/http/latest/http/Client-class.html
67
- [ Foundation URL Loading System ] : https://developer.apple.com/documentation/foundation/url_loading_system
91
+ [ CupertinoWebSocket ] : https://pub.dev/documentation/cupertino_http/latest/cupertino_http/CupertinoWebSocket-class.html
68
92
[ dart:io HttpClient ] : https://api.dart.dev/stable/dart-io/HttpClient-class.html
93
+ [ Foundation URL Loading System ] : https://developer.apple.com/documentation/foundation/url_loading_system
94
+ [ package:http Client ] : https://pub.dev/documentation/http/latest/http/Client-class.html
95
+ [ package:web_socket ] : https://pub.dev/packages/web_socket
96
+ [ WebSocket ] : https://pub.dev/documentation/web_socket/latest/web_socket/WebSocket-class.html
0 commit comments