okws_client 0.1.0 copy "okws_client: ^0.1.0" to clipboard
okws_client: ^0.1.0 copied to clipboard

A simplified WebSocket client with robust reconnection handling, supporting custom headers, ping interval, and backoff strategies.

example/main.dart

import 'package:okws_client/okws_client.dart';

void main() async {
  OkWsClient.init(isLoggingEnable: true);

  final socket = OkWsClient('ws://localhost:8080');

  socket.onStateChange.listen((state) {
    print('State changed: $state');
  });

  socket.onReceive.listen((message) {
    print('Received: $message');
  });

  print('Connecting...');
  await socket.connect();

  print('Sending Hello');
  await socket.send('Hello');

  // Wait a bit
  await Future.delayed(Duration(seconds: 2));

  print('Triggering server-side close by sending "close"');
  await socket.send('close');

  // Wait to see reconnection happen
  await Future.delayed(Duration(seconds: 5));

  print('Sending Hello again (should be reconnected)');
  await socket.send('Hello Again');

  await Future.delayed(Duration(seconds: 2));

  print('Disconnecting manually');
  socket.disconnect();
}
0
likes
160
points
22
downloads

Documentation

API reference

Publisher

verified publisherpub.lwjlol.com

Weekly Downloads

A simplified WebSocket client with robust reconnection handling, supporting custom headers, ping interval, and backoff strategies.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on okws_client