Skip to content
pubscout

web_socket_client

0.2.1, released 2 years ago by felangel.dev

A simple WebSocket client for Dart with automatic reconnection logic.

WASM-ready
$ flutter pub add web_socket_client
Source repository

What it does

Provides a WebSocket client that establishes connections immediately, handles automatic reconnections using backoff strategies, and exposes streams for messages and connection states.

AI-written summary of version 0.2.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need a WebSocket connection with built-in automatic reconnection logic.
  • You want configurable backoff strategies like Constant, Linear, or Binary Exponential.

Skip it when

  • You require complex high-level messaging protocols built on top of WebSockets without writing custom logic.

Strengths

  • Built-in automatic reconnection with customizable backoff strategies.
  • Exposes real-time connection state stream and queryable connection status.
  • Wasm compatibility and support for web platform.

Weaknesses

  • Calling close() permanently terminates reconnection attempts, requiring a new instance to reconnect.
  • Limited to basic WebSocket communication.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
3
final socket = WebSocket(Uri.parse('ws://localhost:8080'));

socket.messages.listen((message) {
  // Handle incoming messages.
});

socket.send('ping');
socket.close();

Alternatives

Packages that do the same job and could replace web_socket_client.

  • mqtt5_client

    A server and browser based MQTT Version 5 client for Dart supporting TCP and WebSockets.

  • mqtt_client

    A Dart MQTT client supporting TCP, WebSocket, secure connections and all QoS levels.

  • centrifuge

    Dart client for real‑time communication with Centrifuge/Centrifugo over WebSockets.

  • socket_io_client

    Dartlang port of socket.io-client for web, flutter, and dartvm

Works with

Packages commonly used together with web_socket_client: ones it builds on, ones built on it, and its own family.