sse
4.2.0, released 7 months ago by tools.dart.dev
Bidirectional Server Sent Events client and server for Dart.
What it does
Provides a client and server implementation of a bidirectional protocol built on Server‑Sent Events. Both sides expose a sink and a stream so messages can be sent and received. Designed for scenarios where WebSockets are unavailable.
AI-written summary of version 4.2.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need real‑time, bidirectional communication in a Dart/Flutter app and WebSockets cannot be used
- Both client and server are written in Dart and can share the same protocol
- You want automatic reconnect and out‑of‑order handling for SSE connections
Skip it when
- You need a general‑purpose SSE library that works with any server implementation
- You can use WebSockets or other protocols that offer richer features
- You require support for non‑Dart backends
Strengths
- Client and server are provided together, ensuring compatibility
- Handles reconnects, out‑of‑order messages and provides logging
- Works on web and server platforms
Weaknesses
- Only works with a matching server from the same package
- Not a generic SSE client for arbitrary servers
- Limited to Dart ecosystem
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 7
import 'package:sse/sse.dart';
void main() async {
final client = SseClient(Uri.parse('https://example.com/sse'));
client.stream.listen((event) => print('Received: $event'));
client.sink.add('Hello server');
}
Alternatives
Packages that do the same job and could replace sse.
- dart_mcp
A Dart library for building Model Context Protocol (MCP) servers and clients.
87Compare - serverpod_client
Base classes for communicating with a Serverpod backend via HTTP and WebSocket
87Compare - http_multi_server
A dart:io HttpServer wrapper that handles requests from multiple servers.
90Compare - eventflux
A Server-Sent Events client for Dart and Flutter with auto-reconnection.
83Compare
Works with
Packages commonly used together with sse: ones it builds on, ones built on it, and its own family.
- poolsse depends on itManage a finite pool of resources to control concurrent operations.
- websse depends on itLightweight bindings for browser APIs via JS interop
- asyncsse depends on itUtility classes and helpers that extend Dart's async library.
- shelfsse depends on itComposable web server middleware for Dart
- loggingsse depends on itProvides configurable logging with levels and stream listeners for Dart apps.
- stream_channelsse depends on itAn abstraction for two-way communication channels based on the Dart Stream class.
- test_apiSame familyThe user facing API for structuring Dart tests and checking expectations.
- shelf_staticSame familyServe static files over HTTP with the shelf package