web_socket_client 0.1.0-dev.1 copy "web_socket_client: ^0.1.0-dev.1" to clipboard
web_socket_client: ^0.1.0-dev.1 copied to clipboard

A simple WebSocket client for Dart which includes automatic reconnection logic.

example/main.dart

// ignore_for_file: avoid_print
import 'package:web_socket_client/web_socket_client.dart';

void main() async {
  // Create a WebSocket client.
  final uri = Uri.parse('ws://localhost:8080');
  const backoff = ConstantBackoff(Duration(seconds: 1));
  final socket = WebSocket(uri, backoff: backoff);

  // Listen for changes in the connection state.
  socket.connection.listen((state) => print('state: "$state"'));

  // Listen for incoming messages.
  socket.messages.listen((message) {
    print('message: "$message"');

    // Send a message to the server.
    socket.send('ping');
  });

  await Future<void>.delayed(const Duration(seconds: 3));

  // Close the connection.
  socket.close();
}
157
likes
0
pub points
96%
popularity

Publisher

verified publisherfelangel.dev

A simple WebSocket client for Dart which includes automatic reconnection logic.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

web_socket_channel

More

Packages that depend on web_socket_client