SessionHostServer<S extends ClientSession> class abstract

A CRDTSocketServer that owns sessions, not a socket.

Everything a server does once a peer is connected — keeping the session map, broadcasting, reporting ServerEvents, tearing sessions down — lives here, and none of it mentions a transport. A concrete host supplies the sessions (createSession) and the handling of its own protocol's session events (handleSessionEvent).

Connections arrive through acceptConnection, which is the seam every transport shares: dart:io hosts call it after upgrading an HttpRequest, and an embedder (another runtime, a test) calls it with whatever TransportConnection it already holds.

Plugins are per host

A ServerSyncPlugin binds to the host it is given to, once. Handing the same plugin instance to two hosts throws a LateInitializationError far from the line that caused it — build a fresh plugin per host.

Inheritance
Implementers

Constructors

SessionHostServer({Compressor? compressor, MessageCodec<Message>? messageCodec, int? maxBufferSize, List<ServerSyncPlugin>? plugins})
A CRDTSocketServer that owns sessions, not a socket.

Properties

compressor → Compressor
Compressor handed to every session this host creates.
final
debugLabel → String
Name of the concrete host, used in diagnostics.
no setter
hashCode → int
The hash code for this object.
no setterinherited
isRunning → bool
Whether this host accepts sessions and does its background work.
no setter
maxBufferSize → int?
Maximum outbound buffer size per client session (bytes).
final
messageCodec → MessageCodec<Message>?
Message codec handed to every session this host creates.
final
ownsTransport → bool
Whether this host owns the transport it serves on.
no setter
plugins → List<ServerSyncPlugin>
The server plugins
finalinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serverEvents → Stream<ServerEvent>
Server events stream
no setteroverride
sessions → Map<String, S>
Active sessions, by id.
no setter
startedMessage → String
Message of the ServerEventType.started event.
no setter
state → SessionHostState
Where this host is in its lifecycle.
no setter
stoppedMessage → String
Message of the ServerEventType.stopped event.
no setter

Methods

acceptConnection(TransportConnection connection, {String? sessionId}) → S?
Register connection as a new session and return it.
addServerEvent(ServerEvent event) → void
Emit a ServerEvent on serverEvents.
broadcastMessage(Message message, {List<String>? excludeClientIds}) → Future<void>
Broadcast a message to all subscribed clients
override
closeAllSessions() → Future<void>
Gracefully close every session.
createSession({required String id, required TransportConnection connection}) → S
Create the session for a newly accepted connection.
dispose() → Future<void>
Dispose the server
override
handleSessionClosed(String sessionId) → void
Drop a session whose event stream ended.
handleSessionError(String sessionId, dynamic error) → void
Report an error on a session's event stream.
handleSessionEvent(SessionEvent event) → FutureOr<void>
Handle a SessionEvent from one of this host's sessions.
handleSessionEventDisconnected(SessionEventGeneric event) → void
Report a disconnect and drop the session.
handleSessionEventError(SessionEventGeneric event) → void
Report a session-level error.
handleSessionEventPingReceived(SessionEventGeneric event) → FutureOr<void>
Report a ping from a client.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onDispose() → Future<void>
Release what this host holds beyond its sessions and plugins.
onRunning() → void
Runs each time this host becomes isRunning: on start, or on the first acceptConnection of a host that does not own its transport.
onStart() → Future<void>
Bring up the transport this host owns. Only called when ownsTransport.
onStarted() → Future<void>
Start serving requests. Only called when ownsTransport.
onStop() → Future<void>
Tear down the transport this host owns. Only called when ownsTransport.
sendMessageToClient(String clientId, Message message) → Future<void>
Send a message to a specific client
override
sessionById(String id) → S?
The session with id, if this host still holds it.
start() → Future<bool>
Start the server
override
startFailureMessage(Object error) → String
Message of the ServerEventType.error event reported when start fails.
stop() → Future<void>
Stop the server
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited