ws
1.0.0, released 3 years ago by plugfox.dev
Cross‑platform WebSocket client with automatic reconnection and metrics
What it does
Provides a lightweight WebSocket client for Dart and Flutter that supports reconnect logic, message streams, and connection state monitoring. It exposes a simple API for connecting, sending, and closing sockets, and offers configurable options per platform.
AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a WebSocket client that works on mobile, desktop, and web without extra dependencies
- You want automatic reconnection with exponential backoff
- You need metrics on sent/received messages and bytes
- You prefer a pure Dart implementation over platform‑specific plugins
Skip it when
- You only need a single‑shot WebSocket connection without reconnection
- You are already using a higher‑level networking library like dio that includes WebSocket support
- You require advanced authentication or subprotocol handling beyond what the options provide
Strengths
- Cross‑platform support (VM and JS)
- Automatic reconnection with backoff
- Stream of state changes and messages
- Configurable options per platform
Weaknesses
- No built‑in authentication or subprotocol helpers
- Limited to WebSocket; no HTTP or REST support
- No code generation or declarative API
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
Add dependency in pubspec.yaml, import 'package:ws/ws.dart'; no special permissions needed
import 'package:ws/ws.dart';
final ws = WebSocket();
await ws.connect('wss://example.com');
ws.stream.listen((msg) => print(msg));
ws.add('Hello');Alternatives
Packages that do the same job and could replace ws.
- web_socket_channel
Standard, widely used WebSocket client with minimal features
83Compare - shelf_web_socket
Server‑side WebSocket handling for Dart servers
80Compare