web_socket_client 0.1.5 copy "web_socket_client: ^0.1.5" to clipboard
web_socket_client: ^0.1.5 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
160
pub points
96%
popularity

Publisher

verified publisherfelangel.dev

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

Repository (GitHub)
View/report issues

Topics

#web-socket #web-socket-client

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

web, web_socket_channel

More

Packages that depend on web_socket_client