web_socket
1.0.1, released 2 years ago by dart.dev
An easy-to-use library for communicating with WebSockets that has multiple implementations.
WASM-readyQuiet but busy
What it does
Provides a simple, well-defined WebSocket interface with consistent behavior across different implementations. It includes conformance-tested implementations for browsers, Cupertino, IO, and OkHttp.
AI-written summary of version 1.0.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a consistent WebSocket interface across multiple platforms and implementations.
- You want an alternative to complex WebSocket packages.
Skip it when
- You require advanced features exclusive to package:web_socket_channel not present here.
Strengths
- Consistent behavior across multiple implementations.
- Passes the same set of conformance tests.
Weaknesses
- Some implementations like OkHttpWebSocket are currently experimental.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
import 'package:web_socket/web_socket.dart';
void main() async {
final socket =
await WebSocket.connect(Uri.parse('wss://ws.postman-echo.com/raw'));
socket.events.listen((e) async {
switch (e) {
case TextDataReceived(text: final text):
print('Received Text: $text');
await socket.close();
case BinaryDataReceived(data: final data):
print('Received Binary: $data');
case CloseReceived(code: final code, reason: final reason):
print('Connection to server closed: $code [$reason]');
}
});
socket.sendText('Hello Dart WebSockets! 🎉');
}Alternatives
Packages that do the same job and could replace web_socket.
- angel3_websocket
WebSockets support and event broadcasting for the Angel3 framework.
77Compare
Works with
Packages commonly used together with web_socket: ones it builds on, ones built on it, and its own family.
- webweb_socket depends on itLightweight bindings for browser APIs via JS interop
- httpSame familyA composable, Future‑based library for making HTTP requests across platforms.
- grpcSame familyDart implementation of gRPC, a high performance universal RPC framework.
- web_socket_channelBuilt on web_socketCross‑platform WebSocket channel wrapper for Dart
- dwdsBuilt on web_socketProxies between the Chrome debug protocol and the Dart VM service protocol.
- cupertino_httpBuilt on web_socketmacOS/iOS Flutter plugin providing access to the Foundation URL Loading System.
- socket_io_clientBuilt on web_socketDartlang port of socket.io-client for web, flutter, and dartvm
- dart_mcp_serverBuilt on web_socketAn MCP server for Dart projects, exposing developer tools to AI models.