websok 1.0.0 copy "websok: ^1.0.0" to clipboard
websok: ^1.0.0 copied to clipboard

outdated

A new Flutter package project.

websok #

A websocket high level abstraction.

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);
  });
}
9
likes
0
pub points
23%
popularity

Publisher

verified publishererik.cat

A new Flutter package project.

Homepage

License

unknown (LICENSE)

Dependencies

flutter, web_socket_channel

More

Packages that depend on websok