Skip to main content

sl_websok 3.0.0 copy "sl_websok: ^3.0.0" to clipboard
sl_websok: ^3.0.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.

example/example.dart

/// For HTML:
/// import 'package:websok/html.dart';
///
/// For IO (Flutter, Dart, etc.)
import 'package:sl_websok/io.dart';

/// The received string.
String? received;

/// Callback to execute when the function is over.
void onData(dynamic message) => received = message;

void main() async {
  /// For HTML: IOWebsok -> HTMLWebsok
  final sok = IOWebsok(host: 'echo.websocket.org', tls: true)
    ..connect()
    ..listen(onData: onData);
  // Send a message.
  sok.send('Hello, world!');
  // Prints the message.
  await Future.delayed(Duration(seconds: 1), () => print(received));
  // Close the connection after 1 sec.
  sok.close();
}
0
likes
150
points
9
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A high level websocket library. Use it when working with websockets to avoid a few boilerplate and make your code look cleaner.

Homepage

License

MIT (license)

Dependencies

meta, web_socket_channel

More

Packages that depend on sl_websok