websok 1.1.0 websok: ^1.1.0 copied to clipboard
A high level websocket library. Use it when working with websockets to avoid a few boilerplate and make your code look cleaner.
websok #
A high level websocket library. Use it when working with websockets to avoid a few boilerplate and make your code look cleaner.
Getting Started #
import 'package:flutter_test/flutter_test.dart';
import 'package:websok/websok.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 {
// ws://127.0.0.1:8181
final sok = Websok(host: '127.0.0.1', port: 8181, tls: false)
..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);
});
}