Data streaming
Build real-time features over websockets with type-safe Dart streams: return a Stream from a server endpoint and listen to it in Flutter, with no manual socket handling or serialization.
Typed streams
Live features usually mean managing raw websocket connections, reconnection logic, and JSON framing on both the server and the client. That is a lot of connection code to maintain, and easy to get wrong.
Serverpod turns a websocket into a typed Dart stream. The server yields model objects; the client awaits them with a plain await for loop; and the framework handles transport, serialization, and reconnection.
How it works
1Create a Stream from an endpoint
Return a Stream and yield typed objects as they arrive.
class ChatEndpoint extends Endpoint {
Stream<ChatMessage> subscribe(Session session, int roomId) async* {
yield* session.messages.createStream<ChatMessage>('room-$roomId');
}
}
2Listen in Flutter
The generated client exposes the same stream, type-safe end-to-end.
await for (var message in client.chat.subscribe(roomId)) {
setState(() => _messages.add(message));
}
3Post updates to the channel
Post from anywhere on the server, and set global to reach subscribers on every server in your cluster.
await session.messages.postMessage('room-$roomId', message, global: true);
Endpoint streams
Any endpoint can return a Stream of your models, and the client receives them as a typed Dart stream, with serialization handled for you.
Two-way streaming
Endpoints can also accept streaming parameters, so the client can push a live stream of input to the server in the same endpoint method.
Cluster-wide messaging
The messaging API lets one server broadcast to subscribers on every other server, which is how you fan out live updates at scale.
Everything included
Stream endpointsWhy Serverpod
Works with
Redis Postgres
Frequently asked questions
Does Serverpod support websockets?
Yes. Streaming endpoints run over websockets, exposed to your app as typed Dart streams.
How do I push real-time updates to a Flutter app?
Return a Stream from an endpoint and await it in the client; new values arrive as the server yields them.
Does it support publish and subscribe messaging?
Yes. The messaging API broadcasts between sessions and across every server in your cluster.
Can the client stream data to the server?
Yes. Endpoints can accept streaming parameters, so input can flow in both directions.
When should I not use this?
For simple request-response calls, a standard endpoint method is simpler. Streams are for continuous, real-time updates.