https://github.com/consoletvs/websok
A high level websocket library. Use it when working with websockets to avoid a few boilerplate and make your code look cleaner.
https://github.com/consoletvs/websok
Last synced: 11 months ago
JSON representation
A high level websocket library. Use it when working with websockets to avoid a few boilerplate and make your code look cleaner.
- Host: GitHub
- URL: https://github.com/consoletvs/websok
- Owner: ConsoleTVs
- License: mit
- Created: 2019-11-17T02:39:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-22T05:41:13.000Z (almost 4 years ago)
- Last Synced: 2025-04-09T00:59:44.027Z (about 1 year ago)
- Language: Dart
- Size: 16.6 KB
- Stars: 7
- Watchers: 2
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# websok
A high level websocket library. Use it when working with websockets
to avoid a few boilerplate and make your code look cleaner.
Supports IO and HTML websockets.
## Getting Started
```dart
/// For HTML:
/// import 'package:websok/html.dart';
///
/// For IO (Flutter, Dart, etc.)
import 'package:websok/io.dart';
/// Testing library.
import 'package:test/test.dart';
/// The received string.
String received;
/// Callback to execute when the function is over.
void onData(dynamic message) => received = message;
void main() {
test('Performs a test websocket connection', () async {
/// For HTML: IOWebsok -> HTMLWebsok
final sok = IOWebsok(host: 'echo.websocket.org', tls: true)
..connect()
..listen(onData: onData);
// Assets the connection.
expect(sok.isActive, true);
// Send a message.
final message = 'Hello, world!';
sok.send(message);
// Check the message.
await Future.delayed(Duration(seconds: 1), () => expect(received, message));
// Close the connection after 1 sec.
sok.close();
// Assets the connection.
expect(sok.isActive, false);
});
}
```